| 1 | // For license of this file, see <project-root-folder>/LICENSE.md.cxx . . $ `<file>/src/librssguard/gui/guiutilities.cpp`/ |
| 2 | |
| 3 | #include "gui/guiutilities.h"cxx . . $ `<file>/src/librssguard/gui/guiutilities.h`/ |
| 4 | |
| 5 | #include "definitions/definitions.h"cxx . . $ `<file>/src/librssguard/definitions/definitions.h`/ |
| 6 | #include "miscellaneous/application.h"cxx . . $ `<file>/src/librssguard/miscellaneous/application.h`/ |
| 7 | #include "miscellaneous/settings.h"cxx . . $ `<file>/src/librssguard/miscellaneous/settings.h`/ |
| 8 | |
| 9 | #include <QDialog> |
| 10 | #include <QMainWindow> |
| 11 | #include <QScreen> |
| 12 | #include <QSettings> |
| 13 | |
| 14 | #if defined(Q_OS_ANDROID) |
| 15 | #include <QApplication> |
| 16 | #include <QDesktopWidget> |
| 17 | #include <QSize> |
| 18 | #endif |
| 19 | |
| 20 | void GuiUtilitiescxx . . $ GuiUtilities#::setLabelAsNoticecxx . . $ GuiUtilities#setLabelAsNotice(c1476c024d375f5b).(QLabelcxx . . $ QLabel#& label, bool is_warning, bool set_margins) { |
| 21 | if (set_margins) { |
| 22 | label.setMargincxx . . $ QLabel#setMargin(d4f767463ce0a6b3).(6); |
| 23 | } |
| 24 | |
| 25 | if (is_warning) { |
| 26 | label.setStyleSheetcxx . . $ QWidget#setStyleSheet(3520e46b33348bf6).(QSLcxx . . $ `src/librssguard/definitions/definitions.h:442:9`!("font-weight: bold; font-style: italic; color: red")); |
| 27 | } |
| 28 | else { |
| 29 | label.setStyleSheetcxx . . $ QWidget#setStyleSheet(3520e46b33348bf6).(QSLcxx . . $ `src/librssguard/definitions/definitions.h:442:9`!("font-style: italic;")); |
| 30 | } |
| 31 | } |
| 32 | |
| 33 | void GuiUtilitiescxx . . $ GuiUtilities#::applyDialogPropertiescxx . . $ GuiUtilities#applyDialogProperties(6e9150cdaac92159).(QWidgetcxx . . $ QWidget#& widget, const QIconcxx . . $ QIcon#& icon, const QStringcxx . . $ QString#& title) { |
| 34 | widget.setWindowFlagscxx . . $ QWidget#setWindowFlags(f800b5e9bc59e42e).(Qtcxx . . $ Qt/::WindowTypecxx . . $ Qt/WindowType#::Dialogcxx . . $ Qt/Dialog. |cxx . . $ Qt/`operator|`(5a3fd7a290f7a57d). Qtcxx . . $ Qt/::WindowTypecxx . . $ Qt/WindowType#::WindowTitleHintcxx . . $ Qt/WindowTitleHint. |cxx . . $ QFlags#`operator|`(2cc1994e0be6f18e). |
| 35 | Qtcxx . . $ Qt/::WindowTypecxx . . $ Qt/WindowType#::WindowMaximizeButtonHintcxx . . $ Qt/WindowMaximizeButtonHint. |cxx . . $ QFlags#`operator|`(2cc1994e0be6f18e). Qtcxx . . $ Qt/::WindowTypecxx . . $ Qt/WindowType#::WindowCloseButtonHintcxx . . $ Qt/WindowCloseButtonHint.); |
| 36 | |
| 37 | widget.setWindowIconcxx . . $ QWidget#setWindowIcon(71dcdac178620ed6).(icon); |
| 38 | |
| 39 | if (!title.isEmptycxx . . $ QString#isEmpty(3482b152b9333168).()) { |
| 40 | widget.setWindowTitlecxx . . $ QWidget#setWindowTitle(3520e46b33348bf6).(title); |
| 41 | } |
| 42 | |
| 43 | loadDialogSizecxx . . $ GuiUtilities#loadDialogSize(74f5d3b5563bf808).(widget); |
| 44 | fixTooBigDialogcxx . . $ GuiUtilities#fixTooBigDialog(c5193997e2df30b4).(widget); |
| 45 | saveSizeOnWidgetClosedcxx . . $ GuiUtilities#saveSizeOnWidgetClosed(74f5d3b5563bf808).(widget); |
| 46 | } |
| 47 | |
| 48 | void GuiUtilitiescxx . . $ GuiUtilities#::fixTooBigDialogcxx . . $ GuiUtilities#fixTooBigDialog(c5193997e2df30b4).(QWidgetcxx . . $ QWidget#& widget, bool move_to_center) { |
| 49 | // We fix too big dialog size or out-of-bounds position. |
| 50 | auto size_widget = widget.frameGeometrycxx . . $ QWidget#frameGeometry(d857385bac04cbf7).().sizecxx . . $ QRect#size(31eef80d4686a819).(); |
| 51 | auto size_widget_original = size_widget; |
| 52 | auto size_screen = widget.screencxx . . $ QWidget#screen(4337f1790dda8b68).()->availableSizecxx . . $ QScreen#availableSize(4b3b776e5ee2b367).(); |
| 53 | |
| 54 | if (size_widget.widthcxx . . $ QSize#width(ea6fe5115c70a13f).() > size_screen.widthcxx . . $ QSize#width(ea6fe5115c70a13f).()) { |
| 55 | size_widget.setWidthcxx . . $ QSize#setWidth(f349c77f591a7878).(size_screen.widthcxx . . $ QSize#width(ea6fe5115c70a13f).() * 0.95); |
| 56 | } |
| 57 | |
| 58 | if (size_widget.heightcxx . . $ QSize#height(ea6fe5115c70a13f).() > size_screen.heightcxx . . $ QSize#height(ea6fe5115c70a13f).()) { |
| 59 | size_widget.setHeightcxx . . $ QSize#setHeight(f349c77f591a7878).(size_screen.heightcxx . . $ QSize#height(ea6fe5115c70a13f).() * 0.95); |
| 60 | } |
| 61 | |
| 62 | bool resized = false; |
| 63 | |
| 64 | if (size_widget !=cxx . . $ `operator!=`(1de60fa97ecbf80a). size_widget_original) { |
| 65 | qWarningNNcxx . . $ `src/librssguard/definitions/definitions.h:417:9`! <<cxx . . $ QDebug#`operator<<`(d8a917b173851aad). LOGSEC_GUIcxx . . $ `src/librssguard/definitions/definitions.h:174:9`! <<cxx . . $ QDebug#`operator<<`(d8a917b173851aad). "Dialog" <<cxx . . $ QDebug#`operator<<`(d8a917b173851aad). QUOTE_W_SPACEcxx . . $ `src/librssguard/definitions/definitions.h:432:9`!(widget.metaObject()->className()) <<cxx . . $ QDebug#`operator<<`(d8a917b173851aad). "was down-sized from" |
| 66 | <<cxx . . $ QDebug#`operator<<`(d8a917b173851aad). QUOTE_W_SPACEcxx . . $ `src/librssguard/definitions/definitions.h:432:9`!(widget.size()) <<cxx . . $ QDebug#`operator<<`(d8a917b173851aad). "to" <<cxx . . $ QDebug#`operator<<`(d8a917b173851aad). QUOTE_W_SPACE_DOTcxx . . $ `src/librssguard/definitions/definitions.h:430:9`!(size_widget); |
| 67 | resized = true; |
| 68 | widget.resizecxx . . $ QWidget#resize(1c5f201b4c2f0aba).(size_widget); |
| 69 | } |
| 70 | |
| 71 | auto pos_widget = widget.poscxx . . $ QWidget#pos(75d69cfbd3c4b2dd).(); |
| 72 | |
| 73 | if ((resized && move_to_center) || pos_widget.xcxx . . $ QPoint#x(ea6fe5115c70a13f).() < 0 || pos_widget.ycxx . . $ QPoint#y(ea6fe5115c70a13f).() < 0) { |
| 74 | // Calculate ideal position for centering the widget. |
| 75 | auto size_parent = widget.parentWidgetcxx . . $ QWidget#parentWidget(27f420ad5cce8994).() != nullptr ? widget.frameGeometrycxx . . $ QWidget#frameGeometry(d857385bac04cbf7).().sizecxx . . $ QRect#size(31eef80d4686a819).() : QSizecxx . . $ QSize#QSize(c0d38f4800714fae).(0, 0); |
| 76 | |
| 77 | // If dialog is bigger than its parent, center it to screen. |
| 78 | // If dialog is smaller than its parent, center to parent. |
| 79 | bool screen_as_parent; |
| 80 | QSizecxx . . $ QSize# size_to_centercxx . . $ QSize#QSize(ced63f7c635d850d).; |
| 81 | |
| 82 | if (size_widget.widthcxx . . $ QSize#width(ea6fe5115c70a13f).() > size_parent.widthcxx . . $ QSize#width(ea6fe5115c70a13f).() || size_widget.heightcxx . . $ QSize#height(ea6fe5115c70a13f).() > size_parent.heightcxx . . $ QSize#height(ea6fe5115c70a13f).()) { |
| 83 | screen_as_parent = true; |
| 84 | size_to_center =cxx . . $ QSize#`operator=`(f8d31cf8106198f1). size_screen; |
| 85 | } |
| 86 | else { |
| 87 | screen_as_parent = false; |
| 88 | size_to_center =cxx . . $ QSize#`operator=`(f8d31cf8106198f1). size_parent; |
| 89 | } |
| 90 | |
| 91 | auto origin_x = (size_to_center.widthcxx . . $ QSize#width(ea6fe5115c70a13f).() - size_widget.widthcxx . . $ QSize#width(ea6fe5115c70a13f).()) / 2.0; |
| 92 | auto origin_y = (size_to_center.heightcxx . . $ QSize#height(ea6fe5115c70a13f).() - size_widget.heightcxx . . $ QSize#height(ea6fe5115c70a13f).()) / 2.0; |
| 93 | auto origin_pos = QPointcxx . . $ QPoint#QPoint(c0d38f4800714fae).(origin_x, origin_y); |
| 94 | |
| 95 | if (origin_pos !=cxx . . $ `operator!=`(ab6369cc90e70b52). pos_widget) { |
| 96 | qWarningNNcxx . . $ `src/librssguard/definitions/definitions.h:417:9`! <<cxx . . $ QDebug#`operator<<`(d8a917b173851aad). LOGSEC_GUIcxx . . $ `src/librssguard/definitions/definitions.h:174:9`! <<cxx . . $ QDebug#`operator<<`(d8a917b173851aad). "Dialog" <<cxx . . $ QDebug#`operator<<`(d8a917b173851aad). QUOTE_W_SPACEcxx . . $ `src/librssguard/definitions/definitions.h:432:9`!(widget.metaObject()->className()) <<cxx . . $ QDebug#`operator<<`(d8a917b173851aad). "was moved from" |
| 97 | <<cxx . . $ QDebug#`operator<<`(d8a917b173851aad). QUOTE_W_SPACEcxx . . $ `src/librssguard/definitions/definitions.h:432:9`!(pos_widget) <<cxx . . $ QDebug#`operator<<`(d8a917b173851aad). "to" <<cxx . . $ QDebug#`operator<<`(d8a917b173851aad). QUOTE_W_SPACE_DOTcxx . . $ `src/librssguard/definitions/definitions.h:430:9`!(origin_pos); |
| 98 | widget.movecxx . . $ QWidget#move(4f9e9534be445c03).(screen_as_parent ? origin_pos : origin_pos +cxx . . $ operator+(c3fbc7b37c9aba6c). widget.parentWidgetcxx . . $ QWidget#parentWidget(27f420ad5cce8994).()->poscxx . . $ QWidget#pos(75d69cfbd3c4b2dd).()); |
| 99 | } |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | void GuiUtilitiescxx . . $ GuiUtilities#::loadDialogSizecxx . . $ GuiUtilities#loadDialogSize(74f5d3b5563bf808).(QWidgetcxx . . $ QWidget#& wdg) { |
| 104 | const QStringcxx . . $ QString# on = wdg.objectNamecxx . . $ QObject#objectName(6ef7b6c27b00b43d).(); |
| 105 | |
| 106 | if (on.isEmptycxx . . $ QString#isEmpty(3482b152b9333168).()) { |
| 107 | qWarningNNcxx . . $ `src/librssguard/definitions/definitions.h:417:9`! <<cxx . . $ QDebug#`operator<<`(d8a917b173851aad). LOGSEC_GUIcxx . . $ `src/librssguard/definitions/definitions.h:174:9`! <<cxx . . $ QDebug#`operator<<`(d8a917b173851aad). "Object of class" <<cxx . . $ QDebug#`operator<<`(d8a917b173851aad). QUOTE_W_SPACEcxx . . $ `src/librssguard/definitions/definitions.h:432:9`!(wdg.metaObject()->className()) |
| 108 | <<cxx . . $ QDebug#`operator<<`(d8a917b173851aad). "has no name, cannot load its size."; |
| 109 | return; |
| 110 | } |
| 111 | |
| 112 | const QStringcxx . . $ QString# key = QSLcxx . . $ `src/librssguard/definitions/definitions.h:442:9`!("%1_size").argcxx . . $ QString#arg(ad0bca07273edcc2).(on); |
| 113 | |
| 114 | wdg.resizecxx . . $ QWidget#resize(1c5f201b4c2f0aba).(qAppcxx . . $ `src/librssguard/miscellaneous/application.h:30:9`!->settingscxx . . $ Application#settings(951936487a2d9252).()->valuecxx . . $ Settings#value(8f1f29a69568d71a).(GROUPcxx . . $ `src/librssguard/miscellaneous/settings.h:32:9`!(DialogGeometries), key, wdgcxx . . $ QVariant#QVariant(b2be42f300f49ebc)..sizecxx . . $ QWidget#size(4b3b776e5ee2b367).()).toSizecxx . . $ QVariant#toSize(4b3b776e5ee2b367).()); |
| 115 | } |
| 116 | |
| 117 | void GuiUtilitiescxx . . $ GuiUtilities#::saveSizeOnWidgetClosedcxx . . $ GuiUtilities#saveSizeOnWidgetClosed(74f5d3b5563bf808).(QWidgetcxx . . $ QWidget#& wdg) { |
| 118 | const QStringcxx . . $ QString# on = wdg.objectNamecxx . . $ QObject#objectName(6ef7b6c27b00b43d).(); |
| 119 | |
| 120 | if (on.isEmptycxx . . $ QString#isEmpty(3482b152b9333168).()) { |
| 121 | qWarningNNcxx . . $ `src/librssguard/definitions/definitions.h:417:9`! <<cxx . . $ QDebug#`operator<<`(d8a917b173851aad). LOGSEC_GUIcxx . . $ `src/librssguard/definitions/definitions.h:174:9`! <<cxx . . $ QDebug#`operator<<`(d8a917b173851aad). "Object of class" <<cxx . . $ QDebug#`operator<<`(d8a917b173851aad). QUOTE_W_SPACEcxx . . $ `src/librssguard/definitions/definitions.h:432:9`!(wdg.metaObject()->className()) |
| 122 | <<cxx . . $ QDebug#`operator<<`(d8a917b173851aad). "has no name, cannot save its size when it closes."; |
| 123 | return; |
| 124 | } |
| 125 | |
| 126 | QDialogcxx . . $ QDialog#* wdg_dialog = qobject_castcxx . . $ qobject_cast(c988cfc0ca08742e).<QDialogcxx . . $ QDialog#*>(&wdg); |
| 127 | |
| 128 | if (wdg_dialog != nullptr) { |
| 129 | QObjectcxx . . $ QObject#::connectcxx . . $ QObject#connect(93770ac28d6bf547).(wdg_dialog, &QDialogcxx . . $ QDialog#::finishedcxx . . $ QDialog#finished(d4f767463ce0a6b3)., [=]() { |
| 130 | const QStringcxx . . $ QString# key = QSLcxx . . $ `src/librssguard/definitions/definitions.h:442:9`!("%1_size").argcxx . . $ QString#arg(ad0bca07273edcc2).(on); |
| 131 | |
| 132 | qDebugNNcxx . . $ `src/librssguard/definitions/definitions.h:413:9`! <<cxx . . $ QDebug#`operator<<`(d8a917b173851aad). LOGSEC_GUIcxx . . $ `src/librssguard/definitions/definitions.h:174:9`! <<cxx . . $ QDebug#`operator<<`(d8a917b173851aad). "Saving size for dialog" <<cxx . . $ QDebug#`operator<<`(d8a917b173851aad). QUOTE_W_SPACE_DOTcxx . . $ `src/librssguard/definitions/definitions.h:430:9`!(on); |
| 133 | qAppcxx . . $ `src/librssguard/miscellaneous/application.h:30:9`!->settingscxx . . $ Application#settings(951936487a2d9252).()->setValuecxx . . $ Settings#setValue(365356ede4ebaabb).(GROUPcxx . . $ `src/librssguard/miscellaneous/settings.h:32:9`!(DialogGeometries), key, wdg_dialogcxx . . $ QVariant#QVariant(b2be42f300f49ebc).->sizecxx . . $ QWidget#size(4b3b776e5ee2b367).()); |
| 134 | }); |
| 135 | } |
| 136 | } |
| 137 | |
| 138 | void GuiUtilitiescxx . . $ GuiUtilities#::restoreStatecxx . . $ GuiUtilities#restoreState(b516affb796b9310).(QWidgetcxx . . $ QWidget#* wdg, QByteArraycxx . . $ QByteArray# state) { |
| 139 | QHashcxx . . $ QHash#<QStringcxx . . $ QString#, QHashcxx . . $ QHash#<QStringcxx . . $ QString#, QVariantcxx . . $ QVariant#>> propscxx . . $ QHash#QHash(ced63f7c635d850d).; |
| 140 | QDataStreamcxx . . $ QDataStream# strcxx . . $ QDataStream#QDataStream(3fbd98f63ed0505e).(&state, QIODevicecxx . . $ QFlags#QFlags(93d577a3e9528307).::OpenModeFlagcxx . . $ QIODeviceBase#OpenModeFlag#::ReadOnlycxx . . $ QIODeviceBase#ReadOnly.); |
| 141 | |
| 142 | str >>cxx . . $ `operator>>`(78ea3f5a704829ce). props; |
| 143 | |
| 144 | QListcxx . . $ QList#<QObjectcxx . . $ QObject#*> to_process = {cxx . . $ QList#QList(b6da5b9a9f304025).wdg}; |
| 145 | |
| 146 | while (!to_process.isEmptycxx . . $ QList#isEmpty(3482b152b9333168).()) { |
| 147 | QObjectcxx . . $ QObject#* act = to_process.takeFirstcxx . . $ QList#takeFirst(5f357b03ed472e5e).(); |
| 148 | |
| 149 | if (props.containscxx . . $ QHash#contains(5247d2cea5ab73ba).(act->objectNamecxx . . $ QObject#objectName(6ef7b6c27b00b43d).())) { |
| 150 | auto saved_props = props.valuecxx . . $ QHash#value(5f65a9ee2c9899ff).(act->objectNamecxx . . $ QObject#objectName(6ef7b6c27b00b43d).()); |
| 151 | auto saved_props_names = saved_props.keyscxx . . $ QHash#keys(bf6c511543d55010).(); |
| 152 | |
| 153 | for (const QStringcxx . . $ QString#& saved_key : saved_props_names) { |
| 154 | act->setPropertycxx . . $ QObject#setProperty(b8a01cfdb0695ee1).(saved_key.toLocal8Bitcxx . . $ QString#toLocal8Bit(ef52b713090bc85a).().constDatacxx . . $ QByteArray#constData(ba32b354807b2b81).(), saved_props.valuecxx . . $ QHash#value(5f65a9ee2c9899ff).(saved_key)); |
| 155 | } |
| 156 | } |
| 157 | |
| 158 | to_process.appendcxx . . $ QList#append(3d2301cfd89f773a).(act->childrencxx . . $ QObject#children(1e4e85a299dc0f9e).()); |
| 159 | } |
| 160 | } |
| 161 | |
| 162 | QByteArraycxx . . $ QByteArray# GuiUtilitiescxx . . $ GuiUtilities#::saveStatecxx . . $ GuiUtilities#saveState(8c206e5b6d250726).(QWidgetcxx . . $ QWidget#* wdg) { |
| 163 | QHashcxx . . $ QHash#<QStringcxx . . $ QString#, QStringListcxx . . $ QStringList#> props_to_serializecxx . . $ QHash#QHash(eb367c5a9e07b320).{{QSLcxx . . $ `src/librssguard/definitions/definitions.h:442:9`!("QCheckBox"), {QSLcxx . . $ `src/librssguard/definitions/definitions.h:442:9`!("checked")}}, |
| 164 | {QSLcxx . . $ `src/librssguard/definitions/definitions.h:442:9`!("QSpinBox"), {QSLcxx . . $ `src/librssguard/definitions/definitions.h:442:9`!("value")}}}; |
| 165 | QHashcxx . . $ QHash#<QStringcxx . . $ QString#, QHashcxx . . $ QHash#<QStringcxx . . $ QString#, QVariantcxx . . $ QVariant#>> propscxx . . $ QHash#QHash(ced63f7c635d850d).; |
| 166 | QListcxx . . $ QList#<QObjectcxx . . $ QObject#*> to_process = {cxx . . $ QList#QList(b6da5b9a9f304025).wdg}; |
| 167 | |
| 168 | while (!to_process.isEmptycxx . . $ QList#isEmpty(3482b152b9333168).()) { |
| 169 | QObjectcxx . . $ QObject#* act = to_process.takeFirstcxx . . $ QList#takeFirst(5f357b03ed472e5e).(); |
| 170 | const QMetaObjectcxx . . $ QMetaObject#* meta = act->metaObjectcxx . . $ QObject#metaObject(216d4151dd9c9333).(); |
| 171 | auto act_props = props_to_serialize.valuecxx . . $ QHash#value(5f65a9ee2c9899ff).(metacxx . . $ QString#QString(85c52e162fed56f9).->classNamecxx . . $ QMetaObject#className(a9f41ea0e82d88cf).()); |
| 172 | QHashcxx . . $ QHash#<QStringcxx . . $ QString#, QVariantcxx . . $ QVariant#> props_objcxx . . $ QHash#QHash(ced63f7c635d850d).; |
| 173 | |
| 174 | for (const QStringcxx . . $ QString#& prop : act_props) { |
| 175 | props_obj.insertcxx . . $ QHash#insert(d77b19c31d2eb147).(prop, act->propertycxx . . $ QObject#property(950ff6813be46b58).(prop.toLocal8Bitcxx . . $ QString#toLocal8Bit(ef52b713090bc85a).().constDatacxx . . $ QByteArray#constData(ba32b354807b2b81).())); |
| 176 | } |
| 177 | |
| 178 | if (!props_obj.isEmptycxx . . $ QHash#isEmpty(3482b152b9333168).()) { |
| 179 | props.insertcxx . . $ QHash#insert(d77b19c31d2eb147).(act->objectNamecxx . . $ QObject#objectName(6ef7b6c27b00b43d).(), props_obj); |
| 180 | } |
| 181 | |
| 182 | to_process.appendcxx . . $ QList#append(3d2301cfd89f773a).(act->childrencxx . . $ QObject#children(1e4e85a299dc0f9e).()); |
| 183 | } |
| 184 | |
| 185 | QByteArraycxx . . $ QByteArray# arrcxx . . $ QByteArray#QByteArray(ced63f7c635d850d).; |
| 186 | QDataStreamcxx . . $ QDataStream# strcxx . . $ QDataStream#QDataStream(3fbd98f63ed0505e).(&arr, QIODevicecxx . . $ QFlags#QFlags(93d577a3e9528307).::OpenModeFlagcxx . . $ QIODeviceBase#OpenModeFlag#::WriteOnlycxx . . $ QIODeviceBase#WriteOnly.); |
| 187 | |
| 188 | str <<cxx . . $ `operator<<`(551a55517285f28a). props; |
| 189 | return arrcxx . . $ QByteArray#QByteArray(9f1b912973d89fea).; |
| 190 | } |