• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • kdeutils
  • Sitemap
  • Contact Us
 

ark

arkviewer.cpp

Go to the documentation of this file.
00001 /*
00002  * ark: A program for modifying archives via a GUI.
00003  *
00004  * Copyright (C) 2004, Henrique Pinto <henrique.pinto@kdemail.net>
00005  *
00006  * This program is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation; either version 2 of the License, or
00009  * (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00019  *
00020  */
00021 
00022 #include "arkviewer.h"
00023 
00024 #include <KLocale>
00025 #include <KMimeTypeTrader>
00026 #include <KMimeType>
00027 #include <KDebug>
00028 #include <KUrl>
00029 #include <KGlobal>
00030 #include <KIconLoader>
00031 #include <KVBox>
00032 
00033 #include <QHBoxLayout>
00034 #include <QFrame>
00035 #include <QLabel>
00036 #include <QDrag>
00037 #include <QMimeData>
00038 #include <QMouseEvent>
00039 
00040 
00041 class DraggableIcon : public QLabel
00042 {
00043     public:
00044         KUrl m_url;
00045 
00046         DraggableIcon(QWidget *parent, KUrl url)
00047             : QLabel(parent), m_url(url)
00048         {
00049 
00050         }
00051 
00052          void mousePressEvent(QMouseEvent *event)
00053          {
00054              kDebug (1601) ;
00055              if (event->button() == Qt::LeftButton) {
00056                  QDrag *drag = new QDrag(this);
00057                  QMimeData *mimeData = new QMimeData;
00058 
00059                  mimeData->setUrls(QList<QUrl>() << m_url);
00060 
00061                  drag->setMimeData(mimeData);
00062 
00063                  drag->exec();
00064              }
00065          }
00066 
00067 };
00068 
00069 
00070 ArkViewer::ArkViewer( QWidget * parent )
00071     : KDialog( parent), m_part( 0 )
00072 {
00073     setButtons( Close );
00074     m_widget = new KVBox( this );
00075     m_widget->layout()->setSpacing( 10 );
00076 
00077     connect( this, SIGNAL( finished() ), this, SLOT( slotFinished() ) );
00078 
00079     setMainWidget( m_widget );
00080 }
00081 
00082 ArkViewer::~ArkViewer()
00083 {
00084 }
00085 
00086 void ArkViewer::slotFinished()
00087 {
00088     delete m_part;
00089     m_part = 0;
00090     delayedDestruct();
00091 }
00092 
00093 bool ArkViewer::view( const QString& filename )
00094 {
00095     KUrl u( filename );
00096 
00097     KMimeType::Ptr mimetype = KMimeType::findByUrl( u, 0, true );
00098 
00099     setCaption( u.fileName() );
00100     // TODO: Load the size from the config file
00101     QSize size = QSize();
00102     if (size.width() < 200)
00103         size = QSize(560, 400);
00104     setInitialSize( size );
00105 
00106     QFrame *header = new QFrame( m_widget );
00107     QHBoxLayout *headerLayout = new QHBoxLayout( header );
00108 
00109     QLabel *iconLabel = new DraggableIcon( header, u);
00110         headerLayout->addWidget(iconLabel);
00111     iconLabel->setPixmap( KIconLoader::global()->loadMimeTypeIcon(mimetype->iconName(), KIconLoader::Desktop ) );
00112     iconLabel->setSizePolicy( QSizePolicy::Fixed, QSizePolicy::Minimum );
00113 
00114     KVBox *headerRight = new KVBox( header );
00115         headerLayout->addWidget(headerRight);
00116     new QLabel( QString( "<qt><b>%1</b></qt>" )
00117                          .arg( KUrl( filename ).fileName() ), headerRight
00118               );
00119     new QLabel( mimetype->comment(), headerRight );
00120 
00121     header->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Maximum );
00122 
00123 
00124     //m_part = KParts::ComponentFactory::createPartInstanceFromQuery<KParts::ReadOnlyPart>( mimetype->name(), QString(), m_widget, this );
00125     m_part = KMimeTypeTrader::self()->createPartInstanceFromQuery<KParts::ReadOnlyPart>(mimetype->name(),
00126             m_widget,
00127             this);
00128 
00129     if ( m_part )
00130     {
00131         m_part->openUrl( filename );
00132         exec();
00133         return true;
00134     }
00135     else
00136     {
00137         return false;
00138     }
00139 }
00140 
00141 #include "arkviewer.moc"

ark

Skip menu "ark"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members

kdeutils

Skip menu "kdeutils"
  • ark
  • kcalc
  • kcharselect
  • kdessh
  • kdf
  • kfloppy
  • kgpg
  • ktimer
  • kwallet
  • okteta
  • printer-applet
  • superkaramba
  • sweeper
Generated for kdeutils by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal