F:/KPlato/koffice/libs/kofficecore/KoDetailsPane.cpp

Aller à la documentation de ce fichier.
00001 /* This file is part of the KDE project
00002    Copyright (C) 2005 Peter Simonsson <psn@linux.se>
00003 
00004    This library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Library General Public
00006    License as published by the Free Software Foundation; either
00007    version 2 of the License, or (at your option) any later version.
00008 
00009    This library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Library General Public License for more details.
00013 
00014    You should have received a copy of the GNU Library General Public License
00015    along with this library; see the file COPYING.LIB.  If not, write to
00016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017  * Boston, MA 02110-1301, USA.
00018 */
00019 #include "KoDetailsPane.h"
00020 
00021 #include <QCheckBox>
00022 #include <QLabel>
00023 #include <QFile>
00024 #include <QImage>
00025 #include <QRect>
00026 #include <QBrush>
00027 #include <QPainter>
00028 #include <QEvent>
00029 #include <QSplitter>
00030 #include <QPixmap>
00031 #include <QStandardItemModel>
00032 
00033 #include <kinstance.h>
00034 #include <klocale.h>
00035 #include <kpushbutton.h>
00036 #include <kconfig.h>
00037 #include <kurl.h>
00038 #include <kfileitem.h>
00039 #include <kio/previewjob.h>
00040 #include <kdebug.h>
00041 #include <ktextbrowser.h>
00042 #include <kapplication.h>
00043 #include <kglobalsettings.h>
00044 #include "KoTemplates.h"
00045 
00046 
00048 // class KoDetailsPane
00050 
00051 class KoDetailsPanePrivate
00052 {
00053   public:
00054     KoDetailsPanePrivate() :
00055       m_instance(0)
00056     {
00057     }
00058 
00059     KInstance* m_instance;
00060     QStandardItemModel* m_model;
00061 };
00062 
00063 KoDetailsPane::KoDetailsPane(QWidget* parent, KInstance* _instance, const QString& header)
00064   : QWidget(parent), Ui_KoDetailsPaneBase()
00065 {
00066   d = new KoDetailsPanePrivate;
00067   d->m_instance = _instance;
00068   d->m_model = new QStandardItemModel;
00069   d->m_model->setHorizontalHeaderItem(0, new QStandardItem(header));
00070 
00071   setupUi(this);
00072 
00073   m_previewLabel->installEventFilter(this);
00074   m_documentList->installEventFilter(this);
00075   m_documentList->setIconSize(QSize(64, 64));
00076   m_documentList->setModel(d->m_model);
00077 
00078   changePalette();
00079 
00080   connect(KGlobalSettings::self(), SIGNAL(kdisplayPaletteChanged()), this, SLOT(changePalette()));
00081 
00082   connect(m_documentList->selectionModel(), SIGNAL(currentChanged(const QModelIndex&, const QModelIndex&)),
00083           this, SLOT(selectionChanged(const QModelIndex&)));
00084   connect(m_documentList, SIGNAL(doubleClicked(const QModelIndex&)),
00085           this, SLOT(openFile(const QModelIndex&)));
00086   connect(m_openButton, SIGNAL(clicked()), this, SLOT(openFile()));
00087 }
00088 
00089 KoDetailsPane::~KoDetailsPane()
00090 {
00091   delete d;
00092 }
00093 
00094 KInstance* KoDetailsPane::instance()
00095 {
00096   return d->m_instance;
00097 }
00098 
00099 bool KoDetailsPane::eventFilter(QObject* watched, QEvent* e)
00100 {
00101   if(watched == m_previewLabel) {
00102     if(e->type() == QEvent::MouseButtonDblClick) {
00103       openFile();
00104     }
00105   }
00106 
00107   if(watched == m_documentList) {
00108     if((e->type() == QEvent::Resize) && isVisible()) {
00109       emit splitterResized(this, m_splitter->sizes());
00110     }
00111 
00112     if((e->type() == QEvent::KeyPress)) {
00113       QKeyEvent* keyEvent = static_cast<QKeyEvent*>(e);
00114 
00115       if(keyEvent->key() == Qt::Key_Enter || keyEvent->key() == Qt::Key_Return) {
00116         openFile();
00117       }
00118     }
00119   }
00120 
00121   return false;
00122 }
00123 
00124 void KoDetailsPane::resizeSplitter(KoDetailsPane* sender, const QList<int>& sizes)
00125 {
00126   if(sender == this)
00127   return;
00128 
00129   m_splitter->setSizes(sizes);
00130 }
00131 
00132 void KoDetailsPane::openFile()
00133 {
00134   QModelIndex index = m_documentList->selectionModel()->currentIndex();
00135   openFile(index);
00136 }
00137 
00138 void KoDetailsPane::changePalette()
00139 {
00140   QPalette p = kapp ? kapp->palette() : palette();
00141   p.setBrush(QColorGroup::Base, p.brush(QPalette::Normal, QColorGroup::Background));
00142   p.setColor(QColorGroup::Text, p.color(QPalette::Normal, QColorGroup::Foreground));
00143   m_detailsLabel->setPalette(p);
00144 }
00145 
00146 QStandardItemModel* KoDetailsPane::model() const
00147 {
00148   return d->m_model;
00149 }
00150 
00151 #include "KoDetailsPane.moc"

Généré le Wed Nov 22 23:41:02 2006 pour KPlato par  doxygen 1.5.1-p1