Charlie Jiang pushed to branch gsoc-2022-chariri-3 at FreeType / FreeType Demo Programs
Commits:
-
68767b6b
by Charlie Jiang at 2022-08-20T00:10:25+08:00
5 changed files:
- src/ftinspect/maingui.cpp
- src/ftinspect/panels/info.cpp
- src/ftinspect/panels/info.hpp
- src/ftinspect/widgets/customwidgets.cpp
- src/ftinspect/widgets/customwidgets.hpp
Changes:
... | ... | @@ -165,7 +165,22 @@ void |
165 | 165 | MainGUI::switchTab()
|
166 | 166 | {
|
167 | 167 | auto isComparator = tabWidget_->currentWidget() == comparatorTab_;
|
168 | - leftWidget_->setVisible(!isComparator);
|
|
168 | + if (!leftWidget_->isVisible() && !isComparator)
|
|
169 | + {
|
|
170 | + // Dirty approach here: When setting the left panel as visible, the main
|
|
171 | + // window will auto-expand. However, we don't want this behaviour.
|
|
172 | + // Doing `resize` right after the `setVisible` is useless since the
|
|
173 | + // layout updating is delayed, so we have to temporarily fix the main window
|
|
174 | + // size, and recover the original min/max size when finished.
|
|
175 | + auto minSize = minimumSize();
|
|
176 | + auto maxSize = maximumSize();
|
|
177 | + setFixedSize(size());
|
|
178 | + leftWidget_->setVisible(true);
|
|
179 | + setMinimumSize(minSize);
|
|
180 | + setMaximumSize(maxSize);
|
|
181 | + }
|
|
182 | + else
|
|
183 | + leftWidget_->setVisible(!isComparator);
|
|
169 | 184 | |
170 | 185 | reloadCurrentTabFont();
|
171 | 186 | }
|
... | ... | @@ -296,6 +296,13 @@ GeneralInfoTab::createLayout() |
296 | 296 | header->setDefaultSectionSize(0);
|
297 | 297 | header->setSectionResizeMode(QHeaderView::Fixed);
|
298 | 298 | |
299 | + leftWidget_ = new QWidget(this);
|
|
300 | + leftScrollArea_ = new UnboundScrollArea(this);
|
|
301 | + leftScrollArea_->setWidgetResizable(true);
|
|
302 | + leftScrollArea_->setWidget(leftWidget_);
|
|
303 | + leftScrollArea_->setStyleSheet("QScrollArea {background-color:transparent;}");
|
|
304 | + leftWidget_->setStyleSheet("background-color:transparent;");
|
|
305 | + |
|
299 | 306 | basicLayout_ = new QGridLayout;
|
300 | 307 | typeEntriesLayout_ = new QGridLayout;
|
301 | 308 | charMapLayout_ = new QHBoxLayout;
|
... | ... | @@ -351,10 +358,12 @@ GeneralInfoTab::createLayout() |
351 | 358 | QSizePolicy::Preferred,
|
352 | 359 | QSizePolicy::Expanding));
|
353 | 360 | |
361 | + leftWidget_->setLayout(leftLayout_);
|
|
362 | + |
|
354 | 363 | rightLayout_->addWidget(charMapGroupBox_);
|
355 | 364 | rightLayout_->addWidget(fixedSizesGroupBox_);
|
356 | 365 | |
357 | - mainLayout_->addLayout(leftLayout_);
|
|
366 | + mainLayout_->addWidget(leftScrollArea_);
|
|
358 | 367 | mainLayout_->addLayout(rightLayout_);
|
359 | 368 | setLayout(mainLayout_);
|
360 | 369 | }
|
... | ... | @@ -748,8 +757,27 @@ PostScriptInfoTab::createLayout() |
748 | 757 | infoGroupBox_ = new QGroupBox(tr("PostScript /FontInfo dictionary"), this);
|
749 | 758 | privateGroupBox_ = new QGroupBox(tr("PostScript /Private dictionary"), this);
|
750 | 759 | |
760 | + infoWidget_ = new QWidget(this);
|
|
761 | + privateWidget_ = new QWidget(this);
|
|
762 | + |
|
763 | + infoScrollArea_ = new UnboundScrollArea(this);
|
|
764 | + infoScrollArea_->setWidget(infoWidget_);
|
|
765 | + infoScrollArea_->setWidgetResizable(true);
|
|
766 | + infoScrollArea_->setStyleSheet("QScrollArea {background-color:transparent;}");
|
|
767 | + infoWidget_->setStyleSheet("background-color:transparent;");
|
|
768 | + infoWidget_->setContentsMargins(0, 0, 0, 0);
|
|
769 | + |
|
770 | + privateScrollArea_ = new UnboundScrollArea(this);
|
|
771 | + privateScrollArea_->setWidget(privateWidget_);
|
|
772 | + privateScrollArea_->setWidgetResizable(true);
|
|
773 | + privateScrollArea_->setStyleSheet("QScrollArea {background-color:transparent;}");
|
|
774 | + privateWidget_->setStyleSheet("background-color:transparent;");
|
|
775 | + privateWidget_->setContentsMargins(0, 0, 0, 0);
|
|
776 | + |
|
751 | 777 | infoLayout_ = new QGridLayout;
|
752 | 778 | privateLayout_ = new QGridLayout;
|
779 | + infoGroupBoxLayout_ = new QHBoxLayout;
|
|
780 | + privateGroupBoxLayout_ = new QHBoxLayout;
|
|
753 | 781 | |
754 | 782 | #define PSI2Row(w) GL2CRow(infoLayout_, w)
|
755 | 783 | #define PSP2Row(w) GL2CRow(privateLayout_, w)
|
... | ... | @@ -796,11 +824,16 @@ PostScriptInfoTab::createLayout() |
796 | 824 | infoLayout_->setColumnStretch(1, 1);
|
797 | 825 | privateLayout_->setColumnStretch(1, 1);
|
798 | 826 | |
799 | - infoGroupBox_->setLayout(infoLayout_);
|
|
800 | - privateGroupBox_->setLayout(privateLayout_);
|
|
827 | + infoWidget_->setLayout(infoLayout_);
|
|
828 | + privateWidget_->setLayout(privateLayout_);
|
|
801 | 829 | infoGroupBox_->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Expanding);
|
802 | 830 | privateGroupBox_->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Expanding);
|
803 | 831 | |
832 | + infoGroupBoxLayout_->addWidget(infoScrollArea_);
|
|
833 | + privateGroupBoxLayout_->addWidget(privateScrollArea_);
|
|
834 | + infoGroupBox_->setLayout(infoGroupBoxLayout_);
|
|
835 | + privateGroupBox_->setLayout(privateGroupBoxLayout_);
|
|
836 | + |
|
804 | 837 | mainLayout_ = new QHBoxLayout;
|
805 | 838 | mainLayout_->addWidget(infoGroupBox_);
|
806 | 839 | mainLayout_->addWidget(privateGroupBox_);
|
... | ... | @@ -7,6 +7,7 @@ |
7 | 7 | #include "abstracttab.hpp"
|
8 | 8 | #include "../engine/fontinfo.hpp"
|
9 | 9 | #include "../models/fontinfomodels.hpp"
|
10 | +#include "../widgets/customwidgets.hpp"
|
|
10 | 11 | |
11 | 12 | #include <vector>
|
12 | 13 | #include <QWidget>
|
... | ... | @@ -111,6 +112,9 @@ private: |
111 | 112 | FixedSizeInfoModel* fixedSizeInfoModel_;
|
112 | 113 | CharMapInfoModel* charMapInfoModel_;
|
113 | 114 | |
115 | + UnboundScrollArea* leftScrollArea_;
|
|
116 | + |
|
117 | + QWidget* leftWidget_;
|
|
114 | 118 | QHBoxLayout* mainLayout_;
|
115 | 119 | QVBoxLayout* leftLayout_;
|
116 | 120 | QVBoxLayout* rightLayout_;
|
... | ... | @@ -234,8 +238,16 @@ private: |
234 | 238 | QGroupBox* infoGroupBox_;
|
235 | 239 | QGroupBox* privateGroupBox_;
|
236 | 240 | |
241 | + QWidget* infoWidget_;
|
|
242 | + QWidget* privateWidget_;
|
|
243 | + |
|
244 | + UnboundScrollArea* infoScrollArea_;
|
|
245 | + UnboundScrollArea* privateScrollArea_;
|
|
246 | + |
|
237 | 247 | QGridLayout* infoLayout_;
|
238 | 248 | QGridLayout* privateLayout_;
|
249 | + QHBoxLayout* infoGroupBoxLayout_;
|
|
250 | + QHBoxLayout* privateGroupBoxLayout_;
|
|
239 | 251 | QHBoxLayout* mainLayout_;
|
240 | 252 | |
241 | 253 | PS_PrivateRec oldFontPrivate_;
|
... | ... | @@ -148,4 +148,32 @@ ZoomSpinBox::stepBy(int steps) |
148 | 148 | }
|
149 | 149 | |
150 | 150 | |
151 | +UnboundScrollArea::UnboundScrollArea(QWidget* parent)
|
|
152 | +: QScrollArea(parent)
|
|
153 | +{
|
|
154 | +}
|
|
155 | + |
|
156 | + |
|
157 | +QSize
|
|
158 | +UnboundScrollArea::sizeHint() const
|
|
159 | +{
|
|
160 | + int fw = 2 * frameWidth();
|
|
161 | + QSize sz(fw, fw);
|
|
162 | + |
|
163 | + int h = fontMetrics().height();
|
|
164 | + |
|
165 | + auto w = widget();
|
|
166 | + if (w)
|
|
167 | + sz += widgetResizable() ? w->sizeHint() : w->size();
|
|
168 | + else
|
|
169 | + sz += QSize(12 * h, 8 * h);
|
|
170 | + |
|
171 | + if (verticalScrollBarPolicy() == Qt::ScrollBarAlwaysOn)
|
|
172 | + sz.setWidth(sz.width() + verticalScrollBar()->sizeHint().width());
|
|
173 | + if (horizontalScrollBarPolicy() == Qt::ScrollBarAlwaysOn)
|
|
174 | + sz.setHeight(sz.height() + horizontalScrollBar()->sizeHint().height());
|
|
175 | + return sz;
|
|
176 | +}
|
|
177 | + |
|
178 | + |
|
151 | 179 | // end of custom_widgets.cpp |
... | ... | @@ -56,4 +56,16 @@ public: |
56 | 56 | };
|
57 | 57 | |
58 | 58 | |
59 | +// https://bugreports.qt.io/browse/QTBUG-10459
|
|
60 | +// https://phabricator.kde.org/D14692
|
|
61 | +class UnboundScrollArea : public QScrollArea
|
|
62 | +{
|
|
63 | + Q_OBJECT
|
|
64 | + |
|
65 | +public:
|
|
66 | + UnboundScrollArea(QWidget* parent);
|
|
67 | + QSize sizeHint() const override;
|
|
68 | +};
|
|
69 | + |
|
70 | + |
|
59 | 71 | // end of custom_widgets.hpp |