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), QMainWindow(parent),
m_ui(new Ui::Squawk), m_ui(new Ui::Squawk),
accounts(0), accounts(0),
preferences(0),
rosterModel(), rosterModel(),
conversations(), conversations(),
contextMenu(new QMenu()), contextMenu(new QMenu()),
@ -55,6 +56,7 @@ Squawk::Squawk(QWidget *parent) :
m_ui->comboBox->setCurrentIndex(static_cast<int>(Shared::Availability::offline)); m_ui->comboBox->setCurrentIndex(static_cast<int>(Shared::Availability::offline));
connect(m_ui->actionAccounts, &QAction::triggered, this, &Squawk::onAccounts); 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->actionAddContact, &QAction::triggered, this, &Squawk::onNewContact);
connect(m_ui->actionAddConference, &QAction::triggered, this, &Squawk::onNewConference); connect(m_ui->actionAddConference, &QAction::triggered, this, &Squawk::onNewConference);
connect(m_ui->actionQuit, &QAction::triggered, this, &Squawk::close); 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) void Squawk::onAccountsSizeChanged(unsigned int size)
{ {
if (size > 0) { if (size > 0) {
@ -173,6 +191,9 @@ void Squawk::closeEvent(QCloseEvent* event)
if (accounts != 0) { if (accounts != 0) {
accounts->close(); accounts->close();
} }
if (preferences != 0) {
preferences->close();
}
for (Conversations::const_iterator itr = conversations.begin(), end = conversations.end(); itr != end; ++itr) { for (Conversations::const_iterator itr = conversations.begin(), end = conversations.end(); itr != end; ++itr) {
disconnect(itr->second, &Conversation::destroyed, this, &Squawk::onConversationClosed); 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; accounts = 0;
} }
void Squawk::onPreferencesClosed()
{
preferences = 0;
}
void Squawk::newAccount(const QMap<QString, QVariant>& account) void Squawk::newAccount(const QMap<QString, QVariant>& account)
{ {
rosterModel.addAccount(account); rosterModel.addAccount(account);

View File

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

View File

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

View File

@ -22,3 +22,4 @@ target_sources(squawk PRIVATE
add_subdirectory(vcard) add_subdirectory(vcard)
add_subdirectory(messageline) 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