Warning, file /office/calligra/libs/main/KoView_p.h 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 Calligra project, made within the KDE community. 0002 * Copyright 2012 Friedrich W. H. Kossebau <kossebau@kde.org> 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 #ifndef KOVIEW_P_H 0021 #define KOVIEW_P_H 0022 0023 // Calligra 0024 #include "KoUnit.h" 0025 #include "KoDocument.h" 0026 // Qt 0027 #include <QActionGroup> 0028 #include <QAction> 0029 0030 0031 // Action group which keeps the actions in sync with the document's unit property 0032 class UnitActionGroup : public QActionGroup 0033 { 0034 Q_OBJECT 0035 public: 0036 explicit UnitActionGroup(KoDocument *document, bool addPixelUnit, QObject* parent = 0) 0037 : QActionGroup(parent) 0038 , m_document(document) 0039 , m_listOptions(addPixelUnit ? KoUnit::ListAll : KoUnit::HidePixel) 0040 { 0041 setExclusive(true); 0042 connect(this, SIGNAL(triggered(QAction*)), SLOT(onTriggered(QAction*))); 0043 connect(document, SIGNAL(unitChanged(KoUnit)), SLOT(onUnitChanged(KoUnit))); 0044 0045 const QStringList unitNames = KoUnit::listOfUnitNameForUi(m_listOptions); 0046 const int currentUnitIndex = m_document->unit().indexInListForUi(m_listOptions); 0047 0048 for (int i = 0; i < unitNames.count(); ++i) { 0049 QAction* action = new QAction(unitNames.at(i), this); 0050 action->setData(i); 0051 action->setCheckable(true); 0052 0053 if (currentUnitIndex == i) { 0054 action->setChecked(true); 0055 } 0056 } 0057 } 0058 0059 private Q_SLOTS: 0060 void onTriggered(QAction *action) 0061 { 0062 m_document->setUnit(KoUnit::fromListForUi(action->data().toInt(), m_listOptions)); 0063 } 0064 0065 void onUnitChanged(const KoUnit &unit) 0066 { 0067 const int indexInList = unit.indexInListForUi(m_listOptions); 0068 0069 foreach (QAction *action, actions()) { 0070 if (action->data().toInt() == indexInList) { 0071 action->setChecked(true); 0072 break; 0073 } 0074 // in case the new unit is not in the list of actions 0075 // this ensures that the action currently checked is unchecked 0076 // once the end of actions has been reached 0077 if (action->isChecked()) { 0078 action->setChecked(false); 0079 } 0080 } 0081 } 0082 0083 private: 0084 KoDocument *m_document; 0085 KoUnit::ListOptions m_listOptions; 0086 }; 0087 0088 #endif