All Classes Namespaces Functions Variables Enumerations Properties Pages
app_util.cpp
1 /*
2 
3 Pencil2D - Traditional Animation Software
4 Copyright (C) 2005-2007 Patrick Corrieri & Pascal Naidon
5 Copyright (C) 2012-2020 Matthew Chiawen Chang
6 
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License
9 as published by the Free Software Foundation; version 2 of the License.
10 
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15 
16 */
17 #include "app_util.h"
18 #include <QAction>
19 #include <QDialog>
20 #include "preferencemanager.h"
21 
22 void hideQuestionMark(QDialog& dlg)
23 {
24  dlg.setWindowFlags(dlg.windowFlags() & ~Qt::WindowContextHelpButtonHint);
25 }
26 
27 void setMenuActionChecked(QAction* action, bool checked)
28 {
29  QSignalBlocker b(action);
30  action->setChecked(checked);
31 }
32 
33 void bindPreferenceSetting(QAction* action, PreferenceManager* prefs, const SETTING& setting)
34 {
35  Q_ASSERT(action->isCheckable());
36  Q_ASSERT(prefs);
37 
38  QSignalBlocker b(action);
39  action->setChecked(prefs->isOn(setting)); // set initial state
40 
41  // 2-way binding
42  QObject::connect(action, &QAction::triggered, [=](bool b) { prefs->set(setting, b); });
43  QObject::connect(prefs, &PreferenceManager::optionChanged, [=](SETTING s)
44  {
45  if (s == setting)
46  {
47  action->setChecked(prefs->isOn(setting));
48  }
49  });
50 }
void triggered(bool checked)
void setChecked(bool)
bool isCheckable() const const
void setWindowFlags(Qt::WindowFlags type)
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)