Engauge Digitizer 2
Loading...
Searching...
No Matches
DlgSettingsAbstractBase.cpp
Go to the documentation of this file.
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 "ButtonWhatsThis.h"
8#include "CmdMediator.h"
10#include "EngaugeAssert.h"
11#include "Logger.h"
12#include "MainWindow.h"
13#include <QColor>
14#include <QComboBox>
15#include <QGraphicsScene>
16#include <QGridLayout>
17#include <QPushButton>
18#include <QScrollArea>
19#include <QSettings>
20#include <QSpacerItem>
21#include <QVBoxLayout>
22#include "Settings.h"
23
24int DlgSettingsAbstractBase::MINIMUM_DIALOG_WIDTH = 380; // May be overridden by subclass
26
28 const QString &dialogName,
30 QDialog (&mainWindow),
31 m_mainWindow (mainWindow),
32 m_cmdMediator (nullptr),
33 m_dialogName (dialogName),
34 m_disableOkAtStartup (true)
35{
36 LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsAbstractBase::DlgSettingsAbstractBase"
37 << " name=" << m_dialogName.toLatin1().data();
38
39 setWindowTitle (title);
40 setModal (true);
41
42 // Linux Mint seems to not show help button
43 //setWindowFlag (Qt::Window, true);
44 //setWindowFlag (Qt::WindowContextHelpButtonHint, true);
45 //setWindowFlag (Qt::WindowCloseButtonHint, true);
46 //setWindowFlag (Qt::WindowMinimizeButtonHint, false);
47 //setWindowFlag (Qt::WindowMaximizeButtonHint, false);
48 setWindowFlags (Qt::Window | Qt::WindowContextHelpButtonHint | Qt::WindowCloseButtonHint);
49}
50
52{
53 LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsAbstractBase::~DlgSettingsAbstractBase"
54 << " name=" << m_dialogName.toLatin1().data();
55}
56
57void DlgSettingsAbstractBase::addPixmap (QGraphicsScene &scene,
58 const QPixmap &pixmap)
59{
60 scene.addPixmap (pixmap);
61 scene.setSceneRect (0,
62 0,
63 pixmap.width(),
64 pixmap.height());
65}
66
68{
69 ENGAUGE_CHECK_PTR (m_cmdMediator);
70
71 return *m_cmdMediator;
72}
73
75 ButtonWhatsThis *button,
76 int row,
77 int column)
78{
79 button = new ButtonWhatsThis ();
80 connect (button, SIGNAL (clicked ()), this, SLOT (slotWhatsThis()));
81 layout->addWidget (button, row, column, 1, 1, Qt::AlignRight | Qt::AlignTop);
82
83 // Prevent huge space after row with this button, especially with DlgSettingsMainWindow
84 layout->setRowStretch (row, 0);
85}
86
88{
89 m_btnOk->setEnabled (enable);
90}
91
93 int minimumWidth,
94 int minimumHeightOrZero)
95{
96 const int STRETCH_OFF = 0, STRETCH_ON = 1;
97
98 m_scroll = new QScrollArea (this);
99 m_scroll->setStyleSheet ("QScrollArea { border: 0; margin: 0; padding: 0;}"); // Need QScrollArea or interior frames are affected
100 m_scroll->setHorizontalScrollBarPolicy (Qt::ScrollBarAlwaysOff);
101 m_scroll->setVerticalScrollBarPolicy (Qt::ScrollBarAsNeeded);
102 m_scroll->setSizePolicy (QSizePolicy::Minimum,
103 QSizePolicy::Minimum);
104 m_scroll->setMinimumWidth (minimumWidth);
105
106 QWidget *viewport = new QWidget (this);
107 m_scroll->setWidget (viewport);
108 m_scroll->setWidgetResizable (true);
109
110 QHBoxLayout *scrollLayout = new QHBoxLayout (this);
111 scrollLayout->addWidget (m_scroll);
112 setLayout (scrollLayout);
113
114 QVBoxLayout *panelLayout = new QVBoxLayout (viewport);
115 viewport->setLayout (panelLayout);
116
117 panelLayout->addWidget (subPanel);
118 panelLayout->setStretch (panelLayout->count () - 1, STRETCH_ON);
119
120 QWidget *panelButtons = new QWidget (this);
121 QHBoxLayout *buttonLayout = new QHBoxLayout (panelButtons);
122
123 createOptionalSaveDefault(buttonLayout);
124
125 QHBoxLayout *layoutRightSide = new QHBoxLayout;
126
127 QWidget *widgetRightSide = new QWidget;
128 widgetRightSide->setLayout (layoutRightSide);
129 buttonLayout->addWidget (widgetRightSide);
130
131 QSpacerItem *spacerExpanding = new QSpacerItem (40, 5, QSizePolicy::Expanding, QSizePolicy::Expanding);
132 layoutRightSide->addItem (spacerExpanding);
133
134 m_btnOk = new QPushButton (tr ("Ok"));
135 m_btnOk->setEnabled (false); // Nothing to save initially
136 layoutRightSide->addWidget (m_btnOk, 0, Qt::AlignRight);
137 connect (m_btnOk, SIGNAL (released ()), this, SLOT (slotOk ()));
138
139 QSpacerItem *spacerFixed = new QSpacerItem (40, 5, QSizePolicy::Fixed, QSizePolicy::Fixed);
140 layoutRightSide->addItem (spacerFixed);
141
142 m_btnCancel = new QPushButton (tr ("Cancel"));
143 layoutRightSide->addWidget (m_btnCancel, 0, Qt::AlignRight);
144 connect (m_btnCancel, SIGNAL (released ()), this, SLOT (slotCancel ()));
145
146 panelLayout->addWidget (panelButtons, STRETCH_ON);
147 panelLayout->setStretch (panelLayout->count () - 1, STRETCH_OFF);
148
149 setSizePolicy (QSizePolicy::Minimum,
150 QSizePolicy::Minimum);
151
152 if (minimumHeightOrZero > 0) {
153 m_scroll->setMinimumHeight (minimumHeightOrZero);
154 }
155}
156
158{
159 return m_mainWindow;
160}
161
163{
164 return m_mainWindow;
165}
166
168{
170 QVariant (COLOR_PALETTE_BLUE));
172 QVariant (COLOR_PALETTE_BLACK));
174 QVariant (COLOR_PALETTE_CYAN));
176 QVariant (COLOR_PALETTE_GOLD));
178 QVariant (COLOR_PALETTE_GREEN));
180 QVariant (COLOR_PALETTE_MAGENTA));
182 QVariant (COLOR_PALETTE_RED));
184 QVariant (COLOR_PALETTE_YELLOW));
185}
186
188{
190 combo.addItem ("Transparent", QVariant (COLOR_PALETTE_TRANSPARENT));
191}
192
193void DlgSettingsAbstractBase::saveGeometryToSettings()
194{
195 // Store the settings for use by showEvent
196 QSettings settings (SETTINGS_ENGAUGE, SETTINGS_DIGITIZER);
197 settings.setValue (m_dialogName, saveGeometry ());
198}
199
204
206{
207 m_disableOkAtStartup = disableOkAtStartup;
208}
209
210void DlgSettingsAbstractBase::hideEvent (QHideEvent * /* event */)
211{
212 saveGeometryToSettings();
213}
214
215void DlgSettingsAbstractBase::showEvent (QShowEvent * /* event */)
216{
217 if (m_disableOkAtStartup) {
218 m_btnOk->setEnabled (false);
219 }
220
221 QSettings settings (SETTINGS_ENGAUGE, SETTINGS_DIGITIZER);
222 if (settings.contains (m_dialogName)) {
223
224 // Restore the settings that were stored by the last call to saveGeometryToSettings
225 restoreGeometry (settings.value (m_dialogName).toByteArray ());
226 }
227}
228
229void DlgSettingsAbstractBase::slotCancel ()
230{
231 LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsAbstractBase::slotCancel";
232
233 hide();
234}
235
236void DlgSettingsAbstractBase::slotOk ()
237{
238 LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsAbstractBase::slotOk";
239
240 // Forward to leaf class
241 handleOk ();
242}
QString colorPaletteToString(ColorPalette colorPalette)
@ COLOR_PALETTE_TRANSPARENT
@ COLOR_PALETTE_GREEN
@ COLOR_PALETTE_MAGENTA
@ COLOR_PALETTE_BLACK
@ COLOR_PALETTE_GOLD
@ COLOR_PALETTE_RED
@ COLOR_PALETTE_BLUE
@ COLOR_PALETTE_CYAN
@ COLOR_PALETTE_YELLOW
#define ENGAUGE_CHECK_PTR(ptr)
Drop in replacement for Q_CHECK_PTR.
log4cpp::Category * mainCat
Definition Logger.cpp:14
const QString SETTINGS_ENGAUGE
const QString SETTINGS_DIGITIZER
Unobtrusive button to trigger QWhatsThis since some operating systems (Linux Mint) do not show WhatsT...
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. Can be increased by finishPa...
void finishPanel(QWidget *subPanel, int minimumWidth=MINIMUM_DIALOG_WIDTH, int minimumHeightOrZero=0)
Add Ok and Cancel buttons to subpanel to get the whole dialog.
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 createWhatsThis(QGridLayout *layout, ButtonWhatsThis *button, int row, int column)
Create a WhatsThis button in a grid layout.
void populateColorComboWithoutTransparent(QComboBox &combo)
Add colors in color palette to combobox, without transparent entry at end.
void addPixmap(QGraphicsScene &scene, const QPixmap &pixmap)
Adds pixmap to the scene.
void enableOk(bool enable)
Let leaf subclass control the Ok button.
void setDisableOkAtStartup(bool disableOkAtStartup)
Override the default Ok button behavior applied in showEvent.
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:95
#define LOG4CPP_INFO_S(logger)
Definition convenience.h:18