Engauge Digitizer 2
Loading...
Searching...
No Matches
DlgSettingsAbstractBase.cpp
1/******************************************************************************************************
2 * (C) 2014 markummitchell@github.com. This file is part of Engauge Digitizer, which is released *
3 * under GNU General Public License version 2 (GPLv2) or (at your option) any later version. See file *
4 * LICENSE or go to gnu.org/licenses for details. Distribution requires prior written permission. *
5 ******************************************************************************************************/
6
7#include "CmdMediator.h"
8#include "DlgSettingsAbstractBase.h"
9#include "EngaugeAssert.h"
10#include "Logger.h"
11#include "MainWindow.h"
12#include <QColor>
13#include <QComboBox>
14#include <QPushButton>
15#include <QSettings>
16#include <QSpacerItem>
17#include <QVBoxLayout>
18
21
23 const QString &dialogName,
24 MainWindow &mainWindow) :
25 QDialog (&mainWindow),
26 m_mainWindow (mainWindow),
27 m_cmdMediator (0),
28 m_dialogName (dialogName),
29 m_disableOkAtStartup (true)
30{
31 LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsAbstractBase::DlgSettingsAbstractBase"
32 << " name=" << m_dialogName.toLatin1().data();
33
34 setWindowTitle (title);
35 setModal (true);
36}
37
38DlgSettingsAbstractBase::~DlgSettingsAbstractBase()
39{
40 LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsAbstractBase::~DlgSettingsAbstractBase"
41 << " name=" << m_dialogName.toLatin1().data();
42}
43
45{
46 ENGAUGE_CHECK_PTR (m_cmdMediator);
47
48 return *m_cmdMediator;
49}
50
52{
53 m_btnOk->setEnabled (enable);
54}
55
57{
58 const int STRETCH_OFF = 0, STRETCH_ON = 1;
59
60 QVBoxLayout *panelLayout = new QVBoxLayout (this);
61
62 setMinimumWidth (MINIMUM_DIALOG_WIDTH);
63 setLayout (panelLayout);
64
65 panelLayout->addWidget (subPanel);
66 panelLayout->setStretch (panelLayout->count () - 1, STRETCH_ON);
67
68 QWidget *panelButtons = new QWidget (this);
69 QHBoxLayout *buttonLayout = new QHBoxLayout (panelButtons);
70
71 createOptionalSaveDefault(buttonLayout);
72
73 QHBoxLayout *layoutRightSide = new QHBoxLayout;
74
75 QWidget *widgetRightSide = new QWidget;
76 widgetRightSide->setLayout (layoutRightSide);
77 buttonLayout->addWidget (widgetRightSide);
78
79 QSpacerItem *spacerExpanding = new QSpacerItem (40, 5, QSizePolicy::Expanding, QSizePolicy::Expanding);
80 layoutRightSide->addItem (spacerExpanding);
81
82 m_btnOk = new QPushButton (tr ("Ok"));
83 m_btnOk->setEnabled (false); // Nothing to save initially
84 layoutRightSide->addWidget (m_btnOk, 0, Qt::AlignRight);
85 connect (m_btnOk, SIGNAL (released ()), this, SLOT (slotOk ()));
86
87 QSpacerItem *spacerFixed = new QSpacerItem (40, 5, QSizePolicy::Fixed, QSizePolicy::Fixed);
88 layoutRightSide->addItem (spacerFixed);
89
90 m_btnCancel = new QPushButton (tr ("Cancel"));
91 layoutRightSide->addWidget (m_btnCancel, 0, Qt::AlignRight);
92 connect (m_btnCancel, SIGNAL (released ()), this, SLOT (slotCancel ()));
93
94 panelLayout->addWidget (panelButtons, STRETCH_ON);
95 panelLayout->setStretch (panelLayout->count () - 1, STRETCH_OFF);
96}
97
99{
100 return m_mainWindow;
101}
102
104{
105 return m_mainWindow;
106}
107
109{
110 combo.addItem (colorPaletteToString (COLOR_PALETTE_BLUE),
111 QVariant (COLOR_PALETTE_BLUE));
112 combo.addItem (colorPaletteToString (COLOR_PALETTE_BLACK),
113 QVariant (COLOR_PALETTE_BLACK));
114 combo.addItem (colorPaletteToString (COLOR_PALETTE_CYAN),
115 QVariant (COLOR_PALETTE_CYAN));
116 combo.addItem (colorPaletteToString (COLOR_PALETTE_GOLD),
117 QVariant (COLOR_PALETTE_GOLD));
118 combo.addItem (colorPaletteToString (COLOR_PALETTE_GREEN),
119 QVariant (COLOR_PALETTE_GREEN));
120 combo.addItem (colorPaletteToString (COLOR_PALETTE_MAGENTA),
121 QVariant (COLOR_PALETTE_MAGENTA));
122 combo.addItem (colorPaletteToString (COLOR_PALETTE_RED),
123 QVariant (COLOR_PALETTE_RED));
124 combo.addItem (colorPaletteToString (COLOR_PALETTE_YELLOW),
125 QVariant (COLOR_PALETTE_YELLOW));
126}
127
129{
131 combo.addItem ("Transparent", QVariant (COLOR_PALETTE_TRANSPARENT));
132}
133
134void DlgSettingsAbstractBase::saveGeometryToSettings()
135{
136 // Store the settings for use by showEvent
137 QSettings settings;
138 settings.setValue (m_dialogName, saveGeometry ());
139}
140
142{
143 m_cmdMediator = &cmdMediator;
144}
145
147{
148 m_disableOkAtStartup = disableOkAtStartup;
149}
150
151void DlgSettingsAbstractBase::showEvent (QShowEvent * /* event */)
152{
153 if (m_disableOkAtStartup) {
154 m_btnOk->setEnabled (false);
155 }
156
157 QSettings settings;
158 if (settings.contains (m_dialogName)) {
159
160 // Restore the settings that were stored by the last call to saveGeometryToSettings
161 restoreGeometry (settings.value (m_dialogName).toByteArray ());
162 }
163}
164
165void DlgSettingsAbstractBase::slotCancel ()
166{
167 LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsAbstractBase::slotCancel";
168
169 saveGeometryToSettings();
170 hide();
171}
172
173void DlgSettingsAbstractBase::slotOk ()
174{
175 LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsAbstractBase::slotOk";
176
177 saveGeometryToSettings();
178
179 // Forward to leaf class
180 handleOk ();
181}
Command queue stack.
Definition CmdMediator.h:24
DlgSettingsAbstractBase(const QString &title, const QString &dialogName, MainWindow &mainWindow)
Single constructor.
void setCmdMediator(CmdMediator &cmdMediator)
Store CmdMediator for easy access by the leaf class.
static int MINIMUM_DIALOG_WIDTH
Dialog layout constant that guarantees every widget has sufficient room.
void populateColorComboWithTransparent(QComboBox &combo)
Add colors in color palette to combobox, with transparent entry at end.
virtual void createOptionalSaveDefault(QHBoxLayout *layout)=0
Let subclass define an optional Save As Default button.
CmdMediator & cmdMediator()
Provide access to Document information wrapped inside CmdMediator.
void populateColorComboWithoutTransparent(QComboBox &combo)
Add colors in color palette to combobox, without transparent entry at end.
void enableOk(bool enable)
Let leaf subclass control the Ok button.
void setDisableOkAtStartup(bool disableOkAtStartup)
Override the default Ok button behavior applied in showEvent.
void finishPanel(QWidget *subPanel)
Add Ok and Cancel buttons to subpanel to get the whole dialog.
virtual void handleOk()=0
Process slotOk.
static int MINIMUM_PREVIEW_HEIGHT
Dialog layout constant that guarantees preview has sufficent room.
MainWindow & mainWindow()
Get method for MainWindow.
Main window consisting of menu, graphics scene, status bar and optional toolbars as a Single Document...
Definition MainWindow.h:78