started to work on settings

This commit is contained in:
Blue 2022-01-16 22:54:57 +03:00
parent 62a59eb7a1
commit 6bee149e6b
Signed by untrusted user: blue
GPG Key ID: 9B203B252A63EE38
10 changed files with 260 additions and 2 deletions

View File

@ -25,6 +25,7 @@ Squawk::Squawk(QWidget *parent) :
QMainWindow(parent),
m_ui(new Ui::Squawk),
accounts(0),
preferences(0),
rosterModel(),
conversations(),
contextMenu(new QMenu()),
@ -55,6 +56,7 @@ Squawk::Squawk(QWidget *parent) :
m_ui->comboBox->setCurrentIndex(static_cast<int>(Shared::Availability::offline));
connect(m_ui->actionAccounts, &QAction::triggered, this, &Squawk::onAccounts);
connect(m_ui->actionPreferences, &QAction::triggered, this, &Squawk::onPreferences);
connect(m_ui->actionAddContact, &QAction::triggered, this, &Squawk::onNewContact);
connect(m_ui->actionAddConference, &QAction::triggered, this, &Squawk::onNewConference);
connect(m_ui->actionQuit, &QAction::triggered, this, &Squawk::close);
@ -117,6 +119,22 @@ void Squawk::onAccounts()
}
}
void Squawk::onPreferences()
{
if (preferences == 0) {
preferences = new Settings();
preferences->setAttribute(Qt::WA_DeleteOnClose);
connect(preferences, &Settings::destroyed, this, &Squawk::onPreferencesClosed);
preferences->show();
} else {
preferences->show();
preferences->raise();
preferences->activateWindow();
}
}
void Squawk::onAccountsSizeChanged(unsigned int size)
{
if (size > 0) {
@ -173,6 +191,9 @@ void Squawk::closeEvent(QCloseEvent* event)
if (accounts != 0) {
accounts->close();
}
if (preferences != 0) {
preferences->close();
}
for (Conversations::const_iterator itr = conversations.begin(), end = conversations.end(); itr != end; ++itr) {
disconnect(itr->second, &Conversation::destroyed, this, &Squawk::onConversationClosed);
@ -190,11 +211,16 @@ void Squawk::closeEvent(QCloseEvent* event)
}
void Squawk::onAccountsClosed(QObject* parent)
void Squawk::onAccountsClosed()
{
accounts = 0;
}
void Squawk::onPreferencesClosed()
{
preferences = 0;
}
void Squawk::newAccount(const QMap<QString, QVariant>& account)
{
rosterModel.addAccount(account);

View File

@ -38,6 +38,7 @@
#include "widgets/joinconference.h"
#include "models/roster.h"
#include "widgets/vcard/vcard.h"
#include "widgets/settings/settings.h"
#include "shared/shared.h"
@ -117,6 +118,7 @@ private:
QScopedPointer<Ui::Squawk> m_ui;
Accounts* accounts;
Settings* preferences;
Models::Roster rosterModel;
Conversations conversations;
QMenu* contextMenu;
@ -136,12 +138,14 @@ protected slots:
private slots:
void onAccounts();
void onPreferences();
void onNewContact();
void onNewConference();
void onNewContactAccepted();
void onJoinConferenceAccepted();
void onAccountsSizeChanged(unsigned int size);
void onAccountsClosed(QObject* parent = 0);
void onAccountsClosed();
void onPreferencesClosed();
void onConversationClosed(QObject* parent = 0);
void onVCardClosed();
void onVCardSave(const Shared::VCard& card, const QString& account);

View File

@ -191,6 +191,7 @@
<string>Settings</string>
</property>
<addaction name="actionAccounts"/>
<addaction name="actionPreferences"/>
</widget>
<widget class="QMenu" name="menuFile">
<property name="title">
@ -245,6 +246,14 @@
<string>Add conference</string>
</property>
</action>
<action name="actionPreferences">
<property name="icon">
<iconset theme="settings-configure"/>
</property>
<property name="text">
<string>Preferences</string>
</property>
</action>
</widget>
<resources>
<include location="../resources/resources.qrc"/>

View File

@ -22,3 +22,4 @@ target_sources(squawk PRIVATE
add_subdirectory(vcard)
add_subdirectory(messageline)
add_subdirectory(settings)

View File

@ -0,0 +1,7 @@
target_sources(squawk PRIVATE
settingslist.h
settingslist.cpp
settings.h
settings.cpp
settings.ui
)

View File

@ -0,0 +1,14 @@
#include "settings.h"
#include "ui_settings.h"
Settings::Settings(QWidget* parent):
QWidget(parent),
m_ui(new Ui::Settings())
{
m_ui->setupUi(this);
}
Settings::~Settings()
{
}

View File

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

View File

@ -0,0 +1,119 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Settings</class>
<widget class="QWidget" name="Settings">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>520</width>
<height>363</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<property name="spacing">
<number>0</number>
</property>
<item row="0" column="0">
<widget class="SettingsList" name="listWidget">
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="lineWidth">
<number>0</number>
</property>
<property name="horizontalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOff</enum>
</property>
<property name="sizeAdjustPolicy">
<enum>QAbstractScrollArea::AdjustToContents</enum>
</property>
<property name="editTriggers">
<set>QAbstractItemView::NoEditTriggers</set>
</property>
<property name="showDropIndicator" stdset="0">
<bool>false</bool>
</property>
<property name="dragDropMode">
<enum>QAbstractItemView::NoDragDrop</enum>
</property>
<property name="verticalScrollMode">
<enum>QAbstractItemView::ScrollPerPixel</enum>
</property>
<property name="movement">
<enum>QListView::Static</enum>
</property>
<property name="flow">
<enum>QListView::TopToBottom</enum>
</property>
<property name="isWrapping" stdset="0">
<bool>false</bool>
</property>
<property name="resizeMode">
<enum>QListView::Adjust</enum>
</property>
<property name="layoutMode">
<enum>QListView::Batched</enum>
</property>
<property name="viewMode">
<enum>QListView::IconMode</enum>
</property>
<property name="uniformItemSizes">
<bool>true</bool>
</property>
<property name="itemAlignment">
<set>Qt::AlignHCenter</set>
</property>
<property name="currentRow">
<number>0</number>
</property>
<item>
<property name="text">
<string>General</string>
</property>
<property name="icon">
<iconset theme="view-list-symbolic">
<normaloff>.</normaloff>.</iconset>
</property>
<property name="flags">
<set>ItemIsSelectable|ItemIsEnabled</set>
</property>
</item>
<item>
<property name="text">
<string>Appearance</string>
</property>
<property name="icon">
<iconset theme="preferences-desktop-theme">
<normaloff>.</normaloff>.</iconset>
</property>
<property name="flags">
<set>ItemIsSelectable|ItemIsEnabled</set>
</property>
</item>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>SettingsList</class>
<extends>QListWidget</extends>
<header location="global">ui/widgets/settings/settingslist.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>

View File

@ -0,0 +1,27 @@
#include "settingslist.h"
SettingsList::SettingsList(QWidget* parent):
QListWidget(parent),
lastWidth(0)
{
}
SettingsList::~SettingsList()
{
}
QStyleOptionViewItem SettingsList::viewOptions() const
{
QStyleOptionViewItem option = QListWidget::viewOptions();
if (!iconSize().isValid()) {
option.decorationSize.setWidth(lastWidth);
}
option.rect.setWidth(lastWidth);
return option;
}
void SettingsList::resizeEvent(QResizeEvent* event)
{
lastWidth = event->size().width();
QListWidget::resizeEvent(event);
}

View File

@ -0,0 +1,25 @@
#ifndef UI_SETTINGSLIST_H
#define UI_SETTINGSLIST_H
#include <QListWidget>
#include <QResizeEvent>
/**
* @todo write docs
*/
class SettingsList : public QListWidget
{
Q_OBJECT
public:
SettingsList(QWidget* parent = nullptr);
~SettingsList();
protected:
QStyleOptionViewItem viewOptions() const override;
void resizeEvent(QResizeEvent * event) override;
private:
int lastWidth;
};
#endif // UI_SETTINGSLIST_H