diff --git a/ui/squawk.cpp b/ui/squawk.cpp index 800f02a..4d22b34 100644 --- a/ui/squawk.cpp +++ b/ui/squawk.cpp @@ -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(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& account) { rosterModel.addAccount(account); diff --git a/ui/squawk.h b/ui/squawk.h index cb93259..26dc0c9 100644 --- a/ui/squawk.h +++ b/ui/squawk.h @@ -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 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); diff --git a/ui/squawk.ui b/ui/squawk.ui index 01ffbba..840dfee 100644 --- a/ui/squawk.ui +++ b/ui/squawk.ui @@ -191,6 +191,7 @@ Settings + @@ -245,6 +246,14 @@ Add conference + + + + + + Preferences + + diff --git a/ui/widgets/CMakeLists.txt b/ui/widgets/CMakeLists.txt index c7e47e0..f3a2afe 100644 --- a/ui/widgets/CMakeLists.txt +++ b/ui/widgets/CMakeLists.txt @@ -22,3 +22,4 @@ target_sources(squawk PRIVATE add_subdirectory(vcard) add_subdirectory(messageline) +add_subdirectory(settings) diff --git a/ui/widgets/settings/CMakeLists.txt b/ui/widgets/settings/CMakeLists.txt new file mode 100644 index 0000000..9f0fa76 --- /dev/null +++ b/ui/widgets/settings/CMakeLists.txt @@ -0,0 +1,7 @@ +target_sources(squawk PRIVATE + settingslist.h + settingslist.cpp + settings.h + settings.cpp + settings.ui +) diff --git a/ui/widgets/settings/settings.cpp b/ui/widgets/settings/settings.cpp new file mode 100644 index 0000000..0397d0c --- /dev/null +++ b/ui/widgets/settings/settings.cpp @@ -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() +{ +} + diff --git a/ui/widgets/settings/settings.h b/ui/widgets/settings/settings.h new file mode 100644 index 0000000..61129d8 --- /dev/null +++ b/ui/widgets/settings/settings.h @@ -0,0 +1,26 @@ +#ifndef SETTINGS_H +#define SETTINGS_H + +#include +#include + +namespace Ui +{ +class Settings; +} + +/** + * @todo write docs + */ +class Settings : public QWidget +{ + Q_OBJECT +public: + Settings(QWidget* parent = nullptr); + ~Settings(); + +private: + QScopedPointer m_ui; +}; + +#endif // SETTINGS_H diff --git a/ui/widgets/settings/settings.ui b/ui/widgets/settings/settings.ui new file mode 100644 index 0000000..f5c4680 --- /dev/null +++ b/ui/widgets/settings/settings.ui @@ -0,0 +1,119 @@ + + + Settings + + + + 0 + 0 + 520 + 363 + + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + QFrame::NoFrame + + + 0 + + + Qt::ScrollBarAlwaysOff + + + QAbstractScrollArea::AdjustToContents + + + QAbstractItemView::NoEditTriggers + + + false + + + QAbstractItemView::NoDragDrop + + + QAbstractItemView::ScrollPerPixel + + + QListView::Static + + + QListView::TopToBottom + + + false + + + QListView::Adjust + + + QListView::Batched + + + QListView::IconMode + + + true + + + Qt::AlignHCenter + + + 0 + + + + General + + + + .. + + + ItemIsSelectable|ItemIsEnabled + + + + + Appearance + + + + .. + + + ItemIsSelectable|ItemIsEnabled + + + + + + + + + SettingsList + QListWidget +
ui/widgets/settings/settingslist.h
+
+
+ + +
diff --git a/ui/widgets/settings/settingslist.cpp b/ui/widgets/settings/settingslist.cpp new file mode 100644 index 0000000..1925632 --- /dev/null +++ b/ui/widgets/settings/settingslist.cpp @@ -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); +} diff --git a/ui/widgets/settings/settingslist.h b/ui/widgets/settings/settingslist.h new file mode 100644 index 0000000..9621c67 --- /dev/null +++ b/ui/widgets/settings/settingslist.h @@ -0,0 +1,25 @@ +#ifndef UI_SETTINGSLIST_H +#define UI_SETTINGSLIST_H + +#include +#include + +/** + * @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