Qt: add scrollbar to settings dialog
This commit is contained in:
parent
3d7eb19abd
commit
ac6e4732f1
|
@ -3020,6 +3020,7 @@ void MainWindow::closeEvent(QCloseEvent *event)
|
||||||
m_settings->setValue("file_browser_table_headers", m_fileTableView->horizontalHeader()->saveState());
|
m_settings->setValue("file_browser_table_headers", m_fileTableView->horizontalHeader()->saveState());
|
||||||
m_settings->setValue("icon_view_zoom", m_lastZoomSliderValue);
|
m_settings->setValue("icon_view_zoom", m_lastZoomSliderValue);
|
||||||
m_settings->setValue("icon_view_thumbnail_type", getCurrentThumbnailTypeString());
|
m_settings->setValue("icon_view_thumbnail_type", getCurrentThumbnailTypeString());
|
||||||
|
m_settings->setValue("options_dialog_geometry", m_viewOptionsDialog->saveGeometry());
|
||||||
|
|
||||||
QMainWindow::closeEvent(event);
|
QMainWindow::closeEvent(event);
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,6 +35,9 @@ extern "C" {
|
||||||
|
|
||||||
#ifdef HAVE_MENU
|
#ifdef HAVE_MENU
|
||||||
|
|
||||||
|
static const int MAX_MIN_WIDTH = 250;
|
||||||
|
static const int MAX_MIN_HEIGHT = 250;
|
||||||
|
|
||||||
QPixmap getColorizedPixmap(const QPixmap& oldPixmap, const QColor& color)
|
QPixmap getColorizedPixmap(const QPixmap& oldPixmap, const QColor& color)
|
||||||
{
|
{
|
||||||
QPixmap pixmap = oldPixmap;
|
QPixmap pixmap = oldPixmap;
|
||||||
|
@ -52,10 +55,74 @@ QColor getLabelColor(const QString& objectName)
|
||||||
return dummyColor.palette().color(QPalette::Foreground);
|
return dummyColor.palette().color(QPalette::Foreground);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* stolen from Qt Creator */
|
||||||
|
class SmartScrollArea : public QScrollArea
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
explicit SmartScrollArea(QWidget *parent) :
|
||||||
|
QScrollArea(parent)
|
||||||
|
{
|
||||||
|
setFrameStyle(QFrame::NoFrame | QFrame::Plain);
|
||||||
|
viewport()->setAutoFillBackground(false);
|
||||||
|
setWidgetResizable(true);
|
||||||
|
}
|
||||||
|
private:
|
||||||
|
void resizeEvent(QResizeEvent *event) final
|
||||||
|
{
|
||||||
|
QWidget *inner = widget();
|
||||||
|
if (inner)
|
||||||
|
{
|
||||||
|
int fw = frameWidth() * 2;
|
||||||
|
QSize innerSize = event->size() - QSize(fw, fw);
|
||||||
|
QSize innerSizeHint = inner->minimumSizeHint();
|
||||||
|
|
||||||
|
if (innerSizeHint.height() > innerSize.height())
|
||||||
|
{ /* Widget wants to be bigger than available space */
|
||||||
|
innerSize.setWidth(innerSize.width() - scrollBarWidth());
|
||||||
|
innerSize.setHeight(innerSizeHint.height());
|
||||||
|
}
|
||||||
|
inner->resize(innerSize);
|
||||||
|
}
|
||||||
|
QScrollArea::resizeEvent(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
QSize minimumSizeHint() const final
|
||||||
|
{
|
||||||
|
QWidget *inner = widget();
|
||||||
|
if (inner) {
|
||||||
|
int fw = frameWidth() * 2;
|
||||||
|
|
||||||
|
QSize minSize = inner->minimumSizeHint();
|
||||||
|
minSize += QSize(fw, fw);
|
||||||
|
minSize += QSize(scrollBarWidth(), 0);
|
||||||
|
minSize.setWidth(qMin(minSize.width(), MAX_MIN_WIDTH));
|
||||||
|
minSize.setHeight(qMin(minSize.height(), MAX_MIN_HEIGHT));
|
||||||
|
return minSize;
|
||||||
|
}
|
||||||
|
return QSize(0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool event(QEvent *event) final
|
||||||
|
{
|
||||||
|
if (event->type() == QEvent::LayoutRequest)
|
||||||
|
updateGeometry();
|
||||||
|
return QScrollArea::event(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
int scrollBarWidth() const
|
||||||
|
{
|
||||||
|
SmartScrollArea *that = const_cast<SmartScrollArea *>(this);
|
||||||
|
QWidgetList list = that->scrollBarWidgets(Qt::AlignRight);
|
||||||
|
if (list.isEmpty())
|
||||||
|
return 0;
|
||||||
|
return list.first()->sizeHint().width();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
ViewOptionsDialog::ViewOptionsDialog(MainWindow *mainwindow, QWidget *parent) :
|
ViewOptionsDialog::ViewOptionsDialog(MainWindow *mainwindow, QWidget *parent) :
|
||||||
QDialog(mainwindow)
|
QDialog(mainwindow)
|
||||||
, m_optionsList(new QListWidget(this))
|
,m_optionsList(new QListWidget(this))
|
||||||
, m_optionsStack(new QStackedWidget(this))
|
,m_optionsStack(new QStackedLayout)
|
||||||
{
|
{
|
||||||
QGridLayout *layout = new QGridLayout(this);
|
QGridLayout *layout = new QGridLayout(this);
|
||||||
QLabel *m_headerLabel = new QLabel(this);
|
QLabel *m_headerLabel = new QLabel(this);
|
||||||
|
@ -66,6 +133,8 @@ ViewOptionsDialog::ViewOptionsDialog(MainWindow *mainwindow, QWidget *parent) :
|
||||||
const int leftMargin = QApplication::style()->pixelMetric(QStyle::PM_LayoutLeftMargin);
|
const int leftMargin = QApplication::style()->pixelMetric(QStyle::PM_LayoutLeftMargin);
|
||||||
int width;
|
int width;
|
||||||
|
|
||||||
|
m_optionsStack->setMargin(0);
|
||||||
|
|
||||||
headerLabelFont.setBold(true);
|
headerLabelFont.setBold(true);
|
||||||
|
|
||||||
// Paranoia: Should a font be set in pixels...
|
// Paranoia: Should a font be set in pixels...
|
||||||
|
@ -106,7 +175,7 @@ ViewOptionsDialog::ViewOptionsDialog(MainWindow *mainwindow, QWidget *parent) :
|
||||||
|
|
||||||
layout->addWidget(m_optionsList, 0, 0, 2, 1);
|
layout->addWidget(m_optionsList, 0, 0, 2, 1);
|
||||||
layout->addLayout(headerHLayout, 0, 1);
|
layout->addLayout(headerHLayout, 0, 1);
|
||||||
layout->addWidget(m_optionsStack, 1, 1);
|
layout->addLayout(m_optionsStack, 1, 1);
|
||||||
|
|
||||||
connect(m_optionsList, SIGNAL(currentRowChanged(int)), m_optionsStack, SLOT(setCurrentIndex(int)));
|
connect(m_optionsList, SIGNAL(currentRowChanged(int)), m_optionsStack, SLOT(setCurrentIndex(int)));
|
||||||
connect(m_optionsList, SIGNAL(currentTextChanged(const QString&)), m_headerLabel, SLOT(setText(const QString&)));
|
connect(m_optionsList, SIGNAL(currentTextChanged(const QString&)), m_headerLabel, SLOT(setText(const QString&)));
|
||||||
|
@ -127,9 +196,11 @@ void ViewOptionsDialog::addCategory(OptionsCategory *category)
|
||||||
|
|
||||||
for (OptionsPage* page : category->pages())
|
for (OptionsPage* page : category->pages())
|
||||||
{
|
{
|
||||||
|
SmartScrollArea *scrollArea = new SmartScrollArea(this);
|
||||||
QWidget *widget = page->widget();
|
QWidget *widget = page->widget();
|
||||||
|
scrollArea->setWidget(widget);
|
||||||
widget->setAutoFillBackground(false);
|
widget->setAutoFillBackground(false);
|
||||||
tabWidget->addTab(widget, page->displayName());
|
tabWidget->addTab(scrollArea, page->displayName());
|
||||||
}
|
}
|
||||||
|
|
||||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 4, 0))
|
#if (QT_VERSION >= QT_VERSION_CHECK(5, 4, 0))
|
||||||
|
|
|
@ -16,7 +16,7 @@ class QSpinBox;
|
||||||
class QWidget;
|
class QWidget;
|
||||||
class OptionsCategory;
|
class OptionsCategory;
|
||||||
class QListWidget;
|
class QListWidget;
|
||||||
class QStackedWidget;
|
class QStackedLayout;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
class ViewOptionsWidget : public QWidget
|
class ViewOptionsWidget : public QWidget
|
||||||
|
@ -58,8 +58,6 @@ class ViewOptionsDialog : public QDialog
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
ViewOptionsDialog(MainWindow *window, QWidget *parent = 0);
|
ViewOptionsDialog(MainWindow *window, QWidget *parent = 0);
|
||||||
// Make sure the settings dialog starts up as small as possible.
|
|
||||||
QSize sizeHint() const final { return minimumSize(); }
|
|
||||||
#ifdef HAVE_MENU
|
#ifdef HAVE_MENU
|
||||||
void repaintIcons();
|
void repaintIcons();
|
||||||
#endif
|
#endif
|
||||||
|
@ -74,7 +72,7 @@ private:
|
||||||
void addCategory(OptionsCategory *category);
|
void addCategory(OptionsCategory *category);
|
||||||
QVector<OptionsCategory*> m_categoryList;
|
QVector<OptionsCategory*> m_categoryList;
|
||||||
QListWidget *m_optionsList;
|
QListWidget *m_optionsList;
|
||||||
QStackedWidget *m_optionsStack;
|
QStackedLayout *m_optionsStack;
|
||||||
#else
|
#else
|
||||||
ViewOptionsWidget *m_viewOptionsWidget;
|
ViewOptionsWidget *m_viewOptionsWidget;
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -522,6 +522,9 @@ static void* ui_companion_qt_init(void)
|
||||||
if (qsettings->contains("save_geometry"))
|
if (qsettings->contains("save_geometry"))
|
||||||
mainwindow->restoreGeometry(qsettings->value("geometry").toByteArray());
|
mainwindow->restoreGeometry(qsettings->value("geometry").toByteArray());
|
||||||
|
|
||||||
|
if (qsettings->contains("options_dialog_geometry"))
|
||||||
|
mainwindow->viewOptionsDialog()->restoreGeometry(qsettings->value("options_dialog_geometry").toByteArray());
|
||||||
|
|
||||||
if (qsettings->contains("save_dock_positions"))
|
if (qsettings->contains("save_dock_positions"))
|
||||||
if (qsettings->contains("dock_positions"))
|
if (qsettings->contains("dock_positions"))
|
||||||
mainwindow->restoreState(qsettings->value("dock_positions").toByteArray());
|
mainwindow->restoreState(qsettings->value("dock_positions").toByteArray());
|
||||||
|
|
Loading…
Reference in New Issue