some more thoughts about settings widgets

This commit is contained in:
Blue 2022-01-19 23:46:42 +03:00
parent 841e526e59
commit a8a7ce2538
Signed by untrusted user: blue
GPG Key ID: 9B203B252A63EE38
12 changed files with 248 additions and 45 deletions

View File

@ -4,4 +4,10 @@ target_sources(squawk PRIVATE
settings.h
settings.cpp
settings.ui
pagegeneral.h
pagegeneral.cpp
pagegeneral.ui
pageappearance.h
pageappearance.cpp
pageappearance.ui
)

View File

@ -0,0 +1,13 @@
#include "pageappearance.h"
#include "ui_pageappearance.h"
PageAppearance::PageAppearance(QWidget* parent):
QWidget(parent),
m_ui(new Ui::PageAppearance())
{
m_ui->setupUi(this);
}
PageAppearance::~PageAppearance()
{
}

View File

@ -0,0 +1,26 @@
#ifndef PAGEAPPEARANCE_H
#define PAGEAPPEARANCE_H
#include <QWidget>
#include <QScopedPointer>
namespace Ui
{
class PageAppearance;
}
/**
* @todo write docs
*/
class PageAppearance : public QWidget
{
Q_OBJECT
public:
PageAppearance(QWidget* parent = nullptr);
~PageAppearance();
private:
QScopedPointer<Ui::PageAppearance> m_ui;
};
#endif // PAGEAPPEARANCE_H

View File

@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>PageAppearance</class>
<widget class="QWidget" name="PageAppearance">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<layout class="QFormLayout" name="formLayout">
<item row="0" column="0">
<widget class="QLabel" name="themeLabel">
<property name="text">
<string>Theme</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="themeInput"/>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

View File

@ -0,0 +1,13 @@
#include "pagegeneral.h"
#include "ui_pagegeneral.h"
PageGeneral::PageGeneral(QWidget* parent):
QWidget(parent),
m_ui(new Ui::PageGeneral())
{
m_ui->setupUi(this);
}
PageGeneral::~PageGeneral()
{
}

View File

@ -0,0 +1,26 @@
#ifndef PAGEGENERAL_H
#define PAGEGENERAL_H
#include <QWidget>
#include <QScopedPointer>
namespace Ui
{
class PageGeneral;
}
/**
* @todo write docs
*/
class PageGeneral : public QWidget
{
Q_OBJECT
public:
PageGeneral(QWidget* parent = nullptr);
~PageGeneral();
private:
QScopedPointer<Ui::PageGeneral> m_ui;
};
#endif // PAGEGENERAL_H

View File

@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>PageGeneral</class>
<widget class="QWidget" name="PageGeneral">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<layout class="QFormLayout" name="formLayout">
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Downloads path</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="downloadsPathInput"/>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

View File

@ -6,9 +6,19 @@ Settings::Settings(QWidget* parent):
m_ui(new Ui::Settings())
{
m_ui->setupUi(this);
connect(m_ui->list, &QListWidget::currentItemChanged, this, &Settings::onCurrentPageChanged);
}
Settings::~Settings()
{
}
void Settings::onCurrentPageChanged(QListWidgetItem* current)
{
if (current != nullptr) {
m_ui->header->setText(current->text());
m_ui->content->setCurrentIndex(m_ui->list->currentRow());
}
}

View File

@ -2,6 +2,7 @@
#define SETTINGS_H
#include <QWidget>
#include <QListWidgetItem>
#include <QScopedPointer>
namespace Ui
@ -19,6 +20,9 @@ public:
Settings(QWidget* parent = nullptr);
~Settings();
protected slots:
void onCurrentPageChanged(QListWidgetItem* current);
private:
QScopedPointer<Ui::Settings> m_ui;
};

View File

@ -6,7 +6,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>465</width>
<width>502</width>
<height>363</height>
</rect>
</property>
@ -21,33 +21,13 @@
<number>0</number>
</property>
<property name="bottomMargin">
<number>7</number>
<number>0</number>
</property>
<property name="spacing">
<number>0</number>
</property>
<item row="2" column="3">
<widget class="QPushButton" name="pushButton">
<property name="text">
<string>Apply</string>
</property>
<property name="icon">
<iconset theme="dialog-ok-apply"/>
</property>
</widget>
</item>
<item row="2" column="2">
<widget class="QPushButton" name="pushButton_2">
<property name="text">
<string>Ok</string>
</property>
<property name="icon">
<iconset theme="dialog-ok"/>
</property>
</widget>
</item>
<item row="0" column="0" rowspan="3">
<widget class="SettingsList" name="listWidget">
<item row="0" column="0" rowspan="2">
<widget class="SettingsList" name="list">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Expanding">
<horstretch>0</horstretch>
@ -66,12 +46,12 @@
<height>16777215</height>
</size>
</property>
<property name="styleSheet">
<string notr="true"/>
</property>
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="lineWidth">
<number>0</number>
</property>
<property name="horizontalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOff</enum>
</property>
@ -103,7 +83,7 @@
<enum>QListView::Adjust</enum>
</property>
<property name="layoutMode">
<enum>QListView::Batched</enum>
<enum>QListView::SinglePass</enum>
</property>
<property name="viewMode">
<enum>QListView::IconMode</enum>
@ -143,24 +123,71 @@
</item>
</widget>
</item>
<item row="1" column="1" colspan="3">
<widget class="QWidget" name="widget" native="true"/>
<item row="0" column="1" rowspan="2" colspan="2">
<widget class="QWidget" name="groupper" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="2" column="2">
<widget class="QPushButton" name="applyButton">
<property name="text">
<string>Apply</string>
</property>
<property name="icon">
<iconset theme="dialog-ok-apply">
<normaloff>.</normaloff>.</iconset>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLabel" name="label">
<item row="2" column="3">
<widget class="QPushButton" name="cancelButton">
<property name="text">
<string>Cancel</string>
</property>
<property name="icon">
<iconset theme="dialog-cancel">
<normaloff>.</normaloff>.</iconset>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QPushButton" name="okButton">
<property name="text">
<string>Ok</string>
</property>
<property name="icon">
<iconset theme="dialog-ok">
<normaloff>.</normaloff>.</iconset>
</property>
</widget>
</item>
<item row="0" column="0" colspan="4">
<widget class="QLabel" name="header">
<property name="styleSheet">
<string notr="true">font-size: 14pt;</string>
</property>
<property name="text">
<string>General</string>
</property>
</widget>
</item>
<item row="2" column="4">
<widget class="QPushButton" name="pushButton_3">
<property name="text">
<string>Cancel</string>
</property>
<property name="icon">
<iconset theme="dialog-cancel"/>
<item row="1" column="0" colspan="4">
<widget class="QStackedWidget" name="content">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<widget class="PageGeneral" name="General" native="true"/>
<widget class="PageAppearance" name="Appearance" native="true"/>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
@ -171,6 +198,16 @@
<extends>QListWidget</extends>
<header location="global">ui/widgets/settings/settingslist.h</header>
</customwidget>
<customwidget>
<class>PageGeneral</class>
<extends>QWidget</extends>
<header location="global">ui/widgets/settings/pagegeneral.h</header>
</customwidget>
<customwidget>
<class>PageAppearance</class>
<extends>QWidget</extends>
<header location="global">ui/widgets/settings/pageappearance.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>

View File

@ -4,6 +4,7 @@ SettingsList::SettingsList(QWidget* parent):
QListWidget(parent),
lastWidth(0)
{
}
SettingsList::~SettingsList()
@ -25,3 +26,13 @@ void SettingsList::resizeEvent(QResizeEvent* event)
lastWidth = event->size().width();
QListWidget::resizeEvent(event);
}
QRect SettingsList::visualRect(const QModelIndex& index) const
{
QRect res = QListWidget::visualRect(index);
if (index.isValid()) {
res.setWidth(lastWidth);
}
return res;
}

View File

@ -17,6 +17,7 @@ public:
protected:
QStyleOptionViewItem viewOptions() const override;
void resizeEvent(QResizeEvent * event) override;
QRect visualRect(const QModelIndex & index) const override;
private:
int lastWidth;