Changeset View
Changeset View
Standalone View
Standalone View
examples/DesignerWidget.cpp
- This file was added.
1 | /* This file is part of the KDE project | ||||
---|---|---|---|---|---|
2 | Copyright (C) 2015 by Adam Pigg <adam@piggz.co.uk> | ||||
3 | | ||||
4 | This library is free software; you can redistribute it and/or | ||||
5 | modify it under the terms of the GNU Library General Public | ||||
6 | License as published by the Free Software Foundation; either | ||||
7 | version 2.1 of the License, or (at your option) any later version. | ||||
8 | | ||||
9 | This library is distributed in the hope that it will be useful, | ||||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||||
12 | Library General Public License for more details. | ||||
13 | | ||||
14 | You should have received a copy of the GNU Library General Public License | ||||
15 | along with this library; see the file COPYING.LIB. If not, write to | ||||
16 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||||
17 | Boston, MA 02110-1301, USA. | ||||
18 | */ | ||||
19 | | ||||
20 | #include "DesignerWidget.h" | ||||
21 | #include "KReportExampleData.h" | ||||
22 | | ||||
23 | #include <KReportDesigner> | ||||
24 | #include <KReportDesignerSectionDetail> | ||||
25 | #include <KReportDesignerSection> | ||||
26 | | ||||
27 | #include <QAction> | ||||
28 | #include <QActionGroup> | ||||
29 | #include <QDockWidget> | ||||
30 | #include <QDomElement> | ||||
31 | #include <QMainWindow> | ||||
32 | #include <QScrollArea> | ||||
33 | #include <QToolBar> | ||||
34 | | ||||
35 | ReportDesignerWidget::ReportDesignerWidget(QWidget *parent) | ||||
36 | : QScrollArea(parent) | ||||
37 | { | ||||
38 | m_reportDesigner = new KReportDesigner(this); | ||||
39 | setWidget(m_reportDesigner); | ||||
40 | | ||||
41 | connect(m_reportDesigner, SIGNAL(itemInserted(QString)), | ||||
42 | this, SLOT(slotItemInserted(QString))); | ||||
43 | connect(m_reportDesigner, SIGNAL(propertySetChanged()), | ||||
44 | this, SLOT(slotDesignerPropertySetChanged())); | ||||
45 | connect(m_reportDesigner, SIGNAL(dirty()), this, SLOT(designDirty())); | ||||
46 | | ||||
47 | m_reportDesigner->setReportData(new KReportExampleData); | ||||
48 | } | ||||
49 | | ||||
50 | ReportDesignerWidget::~ReportDesignerWidget() | ||||
51 | { | ||||
52 | } | ||||
53 | | ||||
54 | QToolBar* ReportDesignerWidget::createMainToolBar(QMainWindow *mainWindow) | ||||
55 | { | ||||
56 | Q_ASSERT(mainWindow); | ||||
57 | if (!m_mainToolBar) { | ||||
58 | m_mainToolBar = mainWindow->addToolBar(tr("Main")); | ||||
59 | QList<QAction*> designerActions = m_reportDesigner->designerActions(); | ||||
60 | foreach(QAction* action, designerActions) { | ||||
61 | m_mainToolBar->addAction(action); | ||||
62 | } | ||||
63 | } | ||||
64 | return m_mainToolBar; | ||||
65 | } | ||||
66 | | ||||
67 | QToolBar* ReportDesignerWidget::createItemsToolBar(QMainWindow *mainWindow) | ||||
68 | { | ||||
69 | if (!m_itemToolBar) { | ||||
70 | m_itemToolBar = mainWindow->addToolBar(tr("Items")); | ||||
71 | QActionGroup *group = new QActionGroup(this); | ||||
72 | QList<QAction*> itemActions = KReportDesigner::itemActions(group); | ||||
73 | foreach(QAction* action, itemActions) { | ||||
74 | m_itemToolBar->addAction(action); | ||||
75 | } | ||||
76 | m_reportDesigner->plugItemActions(itemActions); | ||||
77 | } | ||||
78 | return m_itemToolBar; | ||||
79 | } | ||||
80 | | ||||
81 | QDockWidget* ReportDesignerWidget::createPropertyEditorDockWidget(QMainWindow *mainWindow, | ||||
82 | Qt::DockWidgetArea area) | ||||
83 | { | ||||
84 | if (!m_propertyDock) { | ||||
85 | m_propertyDock = new QDockWidget(tr("Property Editor"), mainWindow); | ||||
86 | m_propertyEditor = new KPropertyEditorView; | ||||
87 | m_propertyEditor->changeSet(m_reportDesigner->propertySet()); | ||||
88 | m_propertyDock->setWidget(m_propertyEditor); | ||||
89 | mainWindow->addDockWidget(area, m_propertyDock); | ||||
90 | m_propertyEditor->resize(200, m_propertyEditor->height()); | ||||
91 | slotDesignerPropertySetChanged(); | ||||
92 | } | ||||
93 | emit designDirty(); | ||||
94 | return m_propertyDock; | ||||
95 | } | ||||
96 | | ||||
97 | void ReportDesignerWidget::slotItemInserted(const QString &itemId) | ||||
98 | { | ||||
99 | QList<QAction*> itemActions = m_itemToolBar->actions(); | ||||
100 | foreach(QAction* action, itemActions) { | ||||
101 | if (action->objectName() == itemId) { | ||||
102 | action->setChecked(false); | ||||
103 | } | ||||
104 | } | ||||
105 | } | ||||
106 | | ||||
107 | void ReportDesignerWidget::slotDesignerPropertySetChanged() | ||||
108 | { | ||||
109 | if (m_propertyEditor) { | ||||
110 | m_propertyEditor->changeSet(m_reportDesigner->itemPropertySet()); | ||||
111 | } | ||||
112 | } | ||||
113 | | ||||
114 | void ReportDesignerWidget::designDirty() | ||||
115 | { | ||||
116 | emit designChanged(m_reportDesigner->document()); | ||||
117 | } | ||||
118 | | ||||
119 | QDomElement ReportDesignerWidget::document() const | ||||
120 | { | ||||
121 | return m_reportDesigner->document(); | ||||
122 | } |