Warning, file /office/calligra/libs/main/KoDetailsPane.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /* This file is part of the KDE project 0002 Copyright (C) 2005 Peter Simonsson <psn@linux.se> 0003 0004 This library is free software; you can redistribute it and/or 0005 modify it under the terms of the GNU Library General Public 0006 License as published by the Free Software Foundation; either 0007 version 2 of the License, or (at your option) any later version. 0008 0009 This library is distributed in the hope that it will be useful, 0010 but WITHOUT ANY WARRANTY; without even the implied warranty of 0011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0012 Library General Public License for more details. 0013 0014 You should have received a copy of the GNU Library General Public License 0015 along with this library; see the file COPYING.LIB. If not, write to 0016 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0017 * Boston, MA 02110-1301, USA. 0018 */ 0019 0020 #include "KoDetailsPane.h" 0021 0022 #include <QStandardItemModel> 0023 #include <QKeyEvent> 0024 0025 //////////////////////////////////// 0026 // class KoDetailsPane 0027 /////////////////////////////////// 0028 0029 class KoDetailsPanePrivate 0030 { 0031 public: 0032 KoDetailsPanePrivate() { 0033 m_model = new QStandardItemModel; 0034 } 0035 ~KoDetailsPanePrivate() { 0036 delete m_model; 0037 } 0038 0039 QStandardItemModel* m_model; 0040 }; 0041 0042 KoDetailsPane::KoDetailsPane(QWidget* parent, const QString& header) 0043 : QWidget(parent), 0044 Ui_KoDetailsPaneBase(), 0045 d(new KoDetailsPanePrivate) 0046 { 0047 d->m_model->setHorizontalHeaderItem(0, new QStandardItem(header)); 0048 0049 setupUi(this); 0050 0051 m_previewLabel->installEventFilter(this); 0052 m_documentList->installEventFilter(this); 0053 m_documentList->setIconSize(QSize(IconExtent, IconExtent)); 0054 m_documentList->setModel(d->m_model); 0055 m_splitter->setSizes(QList<int>() << 2 << 1); 0056 0057 changePalette(); 0058 0059 connect(m_documentList->selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)), 0060 this, SLOT(selectionChanged(QModelIndex))); 0061 connect(m_documentList, SIGNAL(doubleClicked(QModelIndex)), 0062 this, SLOT(openFile(QModelIndex))); 0063 connect(m_openButton, SIGNAL(clicked()), this, SLOT(openFile())); 0064 } 0065 0066 KoDetailsPane::~KoDetailsPane() 0067 { 0068 delete d; 0069 } 0070 0071 bool KoDetailsPane::eventFilter(QObject* watched, QEvent* e) 0072 { 0073 if (watched == m_previewLabel) { 0074 if (e->type() == QEvent::MouseButtonDblClick) { 0075 openFile(); 0076 } 0077 } 0078 0079 if (watched == m_documentList) { 0080 if ((e->type() == QEvent::Resize) && isVisible()) { 0081 emit splitterResized(this, m_splitter->sizes()); 0082 } 0083 0084 if ((e->type() == QEvent::KeyPress)) { 0085 QKeyEvent* keyEvent = static_cast<QKeyEvent*>(e); 0086 0087 if (keyEvent->key() == Qt::Key_Enter || keyEvent->key() == Qt::Key_Return) { 0088 openFile(); 0089 } 0090 } 0091 } 0092 0093 return false; 0094 } 0095 0096 void KoDetailsPane::resizeSplitter(KoDetailsPane* sender, const QList<int>& sizes) 0097 { 0098 if (sender == this) 0099 return; 0100 0101 m_splitter->setSizes(sizes); 0102 } 0103 0104 void KoDetailsPane::openFile() 0105 { 0106 QModelIndex index = m_documentList->selectionModel()->currentIndex(); 0107 openFile(index); 0108 } 0109 0110 void KoDetailsPane::changePalette() 0111 { 0112 QPalette p = palette(); 0113 p.setBrush(QPalette::Base, QColor(Qt::transparent)); 0114 p.setColor(QPalette::Text, p.color(QPalette::Normal, QPalette::Foreground)); 0115 m_detailsLabel->setPalette(p); 0116 } 0117 0118 QStandardItemModel* KoDetailsPane::model() const 0119 { 0120 return d->m_model; 0121 }