1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

Merge pull request #381 from apprb/newsettings_v2

Newsettings v2
This commit is contained in:
Tux3 / Mlkj / !Lev.uXFMLA 2014-10-06 13:29:44 +02:00
commit a85372a5c0
19 changed files with 889 additions and 454 deletions

View File

@ -26,7 +26,10 @@ greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = qtox
TEMPLATE = app
FORMS += \
mainwindow.ui
mainwindow.ui \
widget/form/settings/generalsettings.ui \
widget/form/settings/avsettings.ui \
widget/form/settings/identitysettings.ui
CONFIG += c++11
TRANSLATIONS = translations/de.ts \
@ -84,6 +87,12 @@ win32 {
HEADERS += widget/form/addfriendform.h \
widget/form/chatform.h \
widget/form/groupchatform.h \
widget/form/settingswidget.h \
widget/form/settings/genericsettings.h \
widget/form/settings/generalform.h \
widget/form/settings/identityform.h \
widget/form/settings/privacyform.h \
widget/form/settings/avform.h \
widget/form/filesform.h \
widget/tool/chattextedit.h \
widget/tool/friendrequestdialog.h \
@ -115,7 +124,6 @@ HEADERS += widget/form/addfriendform.h \
corestructs.h \
coredefines.h \
coreav.h \
widget/settingsdialog.h \
widget/tool/chatactions/messageaction.h \
widget/tool/chatactions/filetransferaction.h \
widget/tool/chatactions/systemmessageaction.h \
@ -126,6 +134,11 @@ SOURCES += \
widget/form/addfriendform.cpp \
widget/form/chatform.cpp \
widget/form/groupchatform.cpp \
widget/form/settingswidget.cpp \
widget/form/settings/generalform.cpp \
widget/form/settings/identityform.cpp \
widget/form/settings/privacyform.cpp \
widget/form/settings/avform.cpp \
widget/form/filesform.cpp \
widget/tool/chattextedit.cpp \
widget/tool/friendrequestdialog.cpp \
@ -157,7 +170,6 @@ SOURCES += \
widget/chatareawidget.cpp \
filetransferinstance.cpp \
corestructs.cpp \
widget/settingsdialog.cpp \
widget/tool/chatactions/messageaction.cpp \
widget/tool/chatactions/filetransferaction.cpp \
widget/tool/chatactions/systemmessageaction.cpp \

View File

@ -0,0 +1,57 @@
/*
Copyright (C) 2014 by Project Tox <https://tox.im>
This file is part of qTox, a Qt-based graphical interface for Tox.
This program is libre software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the COPYING file for more details.
*/
#include "avform.h"
#include "widget/camera.h"
#include "ui_avsettings.h"
AVForm::AVForm(Camera* cam) :
GenericForm(tr("Audio/Video settings"), QPixmap(":/img/settings/av.png"))
{
bodyUI = new Ui::AVSettings;
bodyUI->setupUi(this);
camView = new SelfCamView(cam, this);
bodyUI->videoGroup->layout()->addWidget(camView);
camView->hide(); // hide by default
connect(bodyUI->testVideoBtn, &QPushButton::clicked, this, &AVForm::onTestVideoPressed);
}
AVForm::~AVForm()
{
delete bodyUI;
}
void AVForm::showTestVideo()
{
bodyUI->testVideoBtn->setText(tr("Hide video preview","On a button"));
camView->show();
}
void AVForm::closeTestVideo()
{
bodyUI->testVideoBtn->setText(tr("Show video preview","On a button"));
camView->close();
}
void AVForm::onTestVideoPressed()
{
if (camView->isVisible())
closeTestVideo();
else
showTestVideo();
}

View File

@ -0,0 +1,52 @@
/*
Copyright (C) 2014 by Project Tox <https://tox.im>
This file is part of qTox, a Qt-based graphical interface for Tox.
This program is libre software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the COPYING file for more details.
*/
#ifndef AVFORM_H
#define AVFORM_H
#include "genericsettings.h"
#include "widget/selfcamview.h"
#include <QGroupBox>
#include <QVBoxLayout>
#include <QPushButton>
namespace Ui {
class AVSettings;
}
class Camera;
class AVForm : public GenericForm
{
Q_OBJECT
public:
AVForm(Camera* cam);
~AVForm();
private slots:
void onTestVideoPressed();
private:
Ui::AVSettings *bodyUI;
SelfCamView* camView;
void showTestVideo();
void closeTestVideo();
};
#endif

View File

@ -0,0 +1,50 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>AVSettings</class>
<widget class="QWidget" name="AVSettings">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QGroupBox" name="videoGroup">
<property name="title">
<string>Video settings</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QPushButton" name="testVideoBtn">
<property name="text">
<string>Show video preview</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

View File

@ -0,0 +1,70 @@
/*
Copyright (C) 2014 by Project Tox <https://tox.im>
This file is part of qTox, a Qt-based graphical interface for Tox.
This program is libre software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the COPYING file for more details.
*/
#include "ui_generalsettings.h"
#include "generalform.h"
#include "widget/form/settingswidget.h"
#include "widget/widget.h"
#include "misc/settings.h"
#include "misc/smileypack.h"
GeneralForm::GeneralForm() :
GenericForm(tr("General Settings"), QPixmap(":/img/settings/general.png"))
{
bodyUI = new Ui::GeneralSettings;
bodyUI->setupUi(this);
bodyUI->cbEnableIPv6->setChecked(Settings::getInstance().getEnableIPv6());
bodyUI->cbUseTranslations->setChecked(Settings::getInstance().getUseTranslations());
bodyUI->cbMakeToxPortable->setChecked(Settings::getInstance().getMakeToxPortable());
for (auto entry : SmileyPack::listSmileyPacks())
{
bodyUI->smileyPackBrowser->addItem(entry.first, entry.second);
}
bodyUI->smileyPackBrowser->setCurrentIndex(bodyUI->smileyPackBrowser->findData(Settings::getInstance().getSmileyPack()));
connect(bodyUI->cbEnableIPv6, SIGNAL(stateChanged(int)), this, SLOT(onEnableIPv6Updated()));
connect(bodyUI->cbUseTranslations, SIGNAL(stateChanged(int)), this, SLOT(onUseTranslationUpdated()));
connect(bodyUI->cbMakeToxPortable, SIGNAL(stateChanged(int)), this, SLOT(onMakeToxPortableUpdated()));
connect(bodyUI->smileyPackBrowser, SIGNAL(currentIndexChanged(int)), this, SLOT(onSmileyBrowserIndexChanged(int)));
}
GeneralForm::~GeneralForm()
{
delete bodyUI;
}
void GeneralForm::onEnableIPv6Updated()
{
Settings::getInstance().setEnableIPv6(bodyUI->cbEnableIPv6->isChecked());
}
void GeneralForm::onUseTranslationUpdated()
{
Settings::getInstance().setUseTranslations(bodyUI->cbUseTranslations->isChecked());
}
void GeneralForm::onMakeToxPortableUpdated()
{
Settings::getInstance().setMakeToxPortable(bodyUI->cbMakeToxPortable->isChecked());
}
void GeneralForm::onSmileyBrowserIndexChanged(int index)
{
QString filename = bodyUI->smileyPackBrowser->itemData(index).toString();
Settings::getInstance().setSmileyPack(filename);
}

View File

@ -0,0 +1,45 @@
/*
Copyright (C) 2014 by Project Tox <https://tox.im>
This file is part of qTox, a Qt-based graphical interface for Tox.
This program is libre software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the COPYING file for more details.
*/
#ifndef GENERALFORM_H
#define GENERALFORM_H
#include "genericsettings.h"
#include <QComboBox>
#include <QCheckBox>
namespace Ui {
class GeneralSettings;
}
class GeneralForm : public GenericForm
{
Q_OBJECT
public:
GeneralForm();
~GeneralForm();
private slots:
void onEnableIPv6Updated();
void onUseTranslationUpdated();
void onMakeToxPortableUpdated();
void onSmileyBrowserIndexChanged(int index);
private:
Ui::GeneralSettings *bodyUI;
};
#endif

View File

@ -0,0 +1,95 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>GeneralSettings</class>
<widget class="QWidget" name="GeneralSettings">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>527</width>
<height>367</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<property name="leftMargin">
<number>15</number>
</property>
<property name="topMargin">
<number>15</number>
</property>
<property name="rightMargin">
<number>15</number>
</property>
<item>
<widget class="QGroupBox" name="generalGroup">
<property name="title">
<string>General Settings</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="QCheckBox" name="cbEnableIPv6">
<property name="text">
<string extracomment="Text on a checkbox to enable IPv6">Enable IPv6 (recommended)</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="cbUseTranslations">
<property name="text">
<string extracomment="Text on a checkbox to enable translations">Use translations</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="cbMakeToxPortable">
<property name="toolTip">
<string extracomment="describes makeToxPortable checkbox">Save settings to the working directory instead of the usual conf dir</string>
</property>
<property name="text">
<string>Make Tox portable</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="themeGroup">
<property name="title">
<string>Theme</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QLabel" name="smileyPackLabel">
<property name="text">
<string extracomment="Text on smiley pack label">Smiley Pack</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="smileyPackBrowser"/>
</item>
</layout>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

View File

@ -0,0 +1,39 @@
/*
Copyright (C) 2014 by Project Tox <https://tox.im>
This file is part of qTox, a Qt-based graphical interface for Tox.
This program is libre software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the COPYING file for more details.
*/
#ifndef GENERICFORM_H
#define GENERICFORM_H
#include <QWidget>
#include "widget/form/settingswidget.h"
class GenericForm : public QWidget
{
Q_OBJECT
public:
GenericForm(const QString &name, const QPixmap &icon) : formName(name), formIcon(icon) {;}
~GenericForm() {;}
virtual void updateContent() {;}
QString getFormName() {return formName;}
QPixmap getFormIcon() {return formIcon;}
protected:
QString formName;
QPixmap formIcon;
};
#endif

View File

@ -0,0 +1,90 @@
/*
Copyright (C) 2014 by Project Tox <https://tox.im>
This file is part of qTox, a Qt-based graphical interface for Tox.
This program is libre software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the COPYING file for more details.
*/
#include "core.h"
#include "ui_identitysettings.h"
#include "identityform.h"
#include "widget/form/settingswidget.h"
#include "widget/croppinglabel.h"
#include "core.h"
#include <QLabel>
#include <QLineEdit>
#include <QApplication>
#include <QClipboard>
IdentityForm::IdentityForm() :
GenericForm(tr("Your identity"), QPixmap(":/img/settings/identity.png"))
{
bodyUI = new Ui::IdentitySettings;
bodyUI->setupUi(this);
// tox
toxId = new ClickableTE();
QFont small;
small.setPixelSize(13);
small.setKerning(false);
// toxId->setTextInteractionFlags(Qt::TextSelectableByMouse);
toxId->setReadOnly(true);
// toxId->setFrameStyle(QFrame::NoFrame);
// toxId->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
// toxId->setFixedHeight(toxId->document()->size().height()*2);
toxId->setFont(small);
bodyUI->toxGroup->layout()->addWidget(toxId);
connect(bodyUI->toxIdLabel, SIGNAL(clicked()), this, SLOT(copyIdClicked()));
connect(toxId, SIGNAL(clicked()), this, SLOT(copyIdClicked()));
connect(bodyUI->userName, SIGNAL(editingFinished()), this, SLOT(onUserNameEdited()));
connect(bodyUI->statusMessage, SIGNAL(editingFinished()), this, SLOT(onStatusMessageEdited()));
}
IdentityForm::~IdentityForm()
{
}
void IdentityForm::copyIdClicked()
{
toxId->selectAll();
QString txt = toxId->text();
txt.replace('\n',"");
QApplication::clipboard()->setText(txt);
}
void IdentityForm::onUserNameEdited()
{
Core::getInstance()->setUsername(bodyUI->userName->text());
}
void IdentityForm::onStatusMessageEdited()
{
Core::getInstance()->setStatusMessage(bodyUI->statusMessage->text());
}
void IdentityForm::updateContent()
{
toxId->setText(Core::getInstance()->getSelfId().toString());
}
void IdentityForm::setUserName(const QString &name)
{
bodyUI->userName->setText(name);
}
void IdentityForm::setStatusMessage(const QString &msg)
{
bodyUI->statusMessage->setText(msg);
}

View File

@ -0,0 +1,70 @@
/*
Copyright (C) 2014 by Project Tox <https://tox.im>
This file is part of qTox, a Qt-based graphical interface for Tox.
This program is libre software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the COPYING file for more details.
*/
#ifndef IDENTITYFORM_H
#define IDENTITYFORM_H
#include "genericsettings.h"
#include <QGroupBox>
#include <QTextEdit>
#include <QLineEdit>
#include <QLabel>
class CroppingLabel;
namespace Ui {
class IdentitySettings;
}
class ClickableTE : public QLineEdit
{
Q_OBJECT
public:
signals:
void clicked();
protected:
void mouseReleaseEvent(QMouseEvent*) {emit clicked();}
};
class IdentityForm : public GenericForm
{
Q_OBJECT
public:
IdentityForm();
~IdentityForm();
void setUserName(const QString &name);
void setStatusMessage(const QString &msg);
virtual void updateContent();
signals:
void userNameChanged(QString);
void statusMessageChanged(QString);
private slots:
void copyIdClicked();
void onUserNameEdited();
void onStatusMessageEdited();
private:
Ui::IdentitySettings* bodyUI;
ClickableTE* toxId;
};
#endif

View File

@ -0,0 +1,86 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>IdentitySettings</class>
<widget class="QWidget" name="IdentitySettings">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QGroupBox" name="publicGroup">
<property name="title">
<string>Public Information</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QLabel" name="userNameLabel">
<property name="text">
<string>Name</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="userName"/>
</item>
<item>
<widget class="QLabel" name="statusMessageLabel">
<property name="text">
<string>Status</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="statusMessage"/>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="toxGroup">
<property name="title">
<string>Tox ID</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="CroppingLabel" name="toxIdLabel">
<property name="text">
<string>Your Tox ID (click to copy)</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>CroppingLabel</class>
<extends>QLabel</extends>
<header>widget/croppinglabel.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>

View File

@ -0,0 +1,27 @@
/*
Copyright (C) 2014 by Project Tox <https://tox.im>
This file is part of qTox, a Qt-based graphical interface for Tox.
This program is libre software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the COPYING file for more details.
*/
#include "privacyform.h"
#include "widget/form/settingswidget.h"
PrivacyForm::PrivacyForm() :
GenericForm(tr("Privacy settings"), QPixmap(":/img/settings/privacy.png"))
{
}
PrivacyForm::~PrivacyForm()
{
}

View File

@ -0,0 +1,33 @@
/*
Copyright (C) 2014 by Project Tox <https://tox.im>
This file is part of qTox, a Qt-based graphical interface for Tox.
This program is libre software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the COPYING file for more details.
*/
#ifndef PRIVACYFORM_H
#define PRIVACYFORM_H
#include "genericsettings.h"
class PrivacyForm : public GenericForm
{
Q_OBJECT
public:
PrivacyForm();
~PrivacyForm();
private:
};
#endif

View File

@ -0,0 +1,92 @@
/*
Copyright (C) 2014 by Project Tox <https://tox.im>
This file is part of qTox, a Qt-based graphical interface for Tox.
This program is libre software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the COPYING file for more details.
*/
#include "settingswidget.h"
#include "widget/widget.h"
#include "ui_mainwindow.h"
#include "widget/camera.h"
#include "widget/form/settings/generalform.h"
#include "widget/form/settings/identityform.h"
#include "widget/form/settings/privacyform.h"
#include "widget/form/settings/avform.h"
#include <QTabBar>
#include <QStackedWidget>
SettingsWidget::SettingsWidget(Camera* cam, QWidget* parent)
: QWidget(parent)
{
body = new QWidget(this);
QVBoxLayout *bodyLayout = new QVBoxLayout();
body->setLayout(bodyLayout);
head = new QWidget(this);
QHBoxLayout *headLayout = new QHBoxLayout();
head->setLayout(headLayout);
imgLabel = new QLabel();
headLayout->addWidget(imgLabel);
nameLabel = new QLabel();
QFont bold;
bold.setBold(true);
nameLabel->setFont(bold);
headLayout->addWidget(nameLabel);
headLayout->addStretch(1);
settingsWidgets = new QStackedWidget;
bodyLayout->addWidget(settingsWidgets);
tabBar = new QTabBar;
bodyLayout->addWidget(tabBar);
GeneralForm *gfrm = new GeneralForm;
ifrm = new IdentityForm;
PrivacyForm *pfrm = new PrivacyForm;
AVForm *avfrm = new AVForm(cam);
GenericForm *cfgForms[] = {gfrm, ifrm, pfrm, avfrm};
for (auto cfgForm : cfgForms)
{
tabBar->addTab(cfgForm->getFormIcon(), "");
settingsWidgets->addWidget(cfgForm);
}
tabBar->setIconSize(QSize(20, 20));
tabBar->setShape(QTabBar::RoundedSouth);
connect(tabBar, SIGNAL(currentChanged(int)), this, SLOT(onTabChanged(int)));
}
SettingsWidget::~SettingsWidget()
{
}
void SettingsWidget::show(Ui::MainWindow& ui)
{
ui.mainContent->layout()->addWidget(body);
ui.mainHead->layout()->addWidget(head);
body->show();
head->show();
onTabChanged(tabBar->currentIndex());
}
void SettingsWidget::onTabChanged(int index)
{
this->settingsWidgets->setCurrentIndex(index);
GenericForm *currentWidget = static_cast<GenericForm*>(this->settingsWidgets->widget(index));
currentWidget->updateContent();
nameLabel->setText(currentWidget->getFormName());
imgLabel->setPixmap(currentWidget->getFormIcon().scaledToHeight(40, Qt::SmoothTransformation));
}

View File

@ -0,0 +1,55 @@
/*
Copyright (C) 2014 by Project Tox <https://tox.im>
This file is part of qTox, a Qt-based graphical interface for Tox.
This program is libre software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the COPYING file for more details.
*/
#ifndef SETTINGSWIDGET_H
#define SETTINGSWIDGET_H
#include <QHBoxLayout>
#include <QPushButton>
class Camera;
class GenericForm;
class GeneralForm;
class IdentityForm;
class PrivacyForm;
class AVForm;
class QTabBar;
class QStackedWidget;
class QLabel;
namespace Ui {class MainWindow;}
class SettingsWidget : public QWidget
{
Q_OBJECT
public:
SettingsWidget(Camera* cam, QWidget* parent = nullptr);
~SettingsWidget();
void show(Ui::MainWindow &ui);
IdentityForm *getIdentityForm() {return ifrm;}
private slots:
void onTabChanged(int);
private:
QWidget *head, *body; // keep the others private
IdentityForm *ifrm;
QStackedWidget *settingsWidgets;
QTabBar *tabBar;
QLabel *nameLabel, *imgLabel;
};
#endif // SETTINGSWIDGET_H

View File

@ -1,380 +0,0 @@
#include "settingsdialog.h"
#include "misc/settings.h"
#include "widget.h"
#include "camera.h"
#include "selfcamview.h"
#include "core.h"
#include "misc/smileypack.h"
#include <QListWidget>
#include <QListWidgetItem>
#include <QStackedWidget>
#include <QPushButton>
#include <QBoxLayout>
#include <QLabel>
#include <QGroupBox>
#include <QCheckBox>
#include <QLineEdit>
#include <QComboBox>
// =======================================
// settings pages
//========================================
class GeneralPage : public QWidget
{
Q_OBJECT
public:
GeneralPage(QWidget *parent = 0) :
QWidget(parent)
{
QGroupBox *group = new QGroupBox(tr("General Settings"), this);
enableIPv6 = new QCheckBox(this);
enableIPv6->setText(tr("Enable IPv6 (recommended)","Text on a checkbox to enable IPv6"));
useTranslations = new QCheckBox(this);
useTranslations->setText(tr("Use translations","Text on a checkbox to enable translations"));
makeToxPortable = new QCheckBox(this);
makeToxPortable->setText(tr("Make Tox portable","Text on a checkbox to make qTox a portable application"));
makeToxPortable->setToolTip(tr("Save settings to the working directory instead of the usual conf dir","describes makeToxPortable checkbox"));
QVBoxLayout *vLayout = new QVBoxLayout();
vLayout->addWidget(enableIPv6);
vLayout->addWidget(useTranslations);
vLayout->addWidget(makeToxPortable);
group->setLayout(vLayout);
// theme
QGroupBox* themeGroup = new QGroupBox(tr("Theme"));
QLabel* smileyLabel = new QLabel(tr("Smiley Pack"));
smileyPack = new QComboBox(this);
auto smileyPacks = SmileyPack::listSmileyPacks();
for(auto pack : smileyPacks)
smileyPack->addItem(QString("%1 (%2)").arg(pack.first).arg(pack.second), pack.second);
QVBoxLayout* themeLayout = new QVBoxLayout();
themeLayout->addWidget(smileyLabel);
themeLayout->addWidget(smileyPack);
themeGroup->setLayout(themeLayout);
QVBoxLayout *mainLayout = new QVBoxLayout();
mainLayout->addWidget(group);
mainLayout->addWidget(themeGroup);
mainLayout->addStretch(1);
setLayout(mainLayout);
}
QCheckBox* enableIPv6;
QCheckBox* useTranslations;
QCheckBox* makeToxPortable;
QComboBox* smileyPack;
};
class IdentityPage : public QWidget
{
Q_OBJECT
public:
IdentityPage(QWidget* parent = 0) :
QWidget(parent)
{
// public
QGroupBox *publicGroup = new QGroupBox(tr("Public Information"), this);
QLabel* userNameLabel = new QLabel(tr("Name","Username/nick"), this);
userName = new QLineEdit(this);
QLabel* statusMessageLabel = new QLabel(tr("Status","Status message"), this);
statusMessage = new QLineEdit(this);
QVBoxLayout *vLayout = new QVBoxLayout();
vLayout->addWidget(userNameLabel);
vLayout->addWidget(userName);
vLayout->addWidget(statusMessageLabel);
vLayout->addWidget(statusMessage);
publicGroup->setLayout(vLayout);
// tox
QGroupBox* toxGroup = new QGroupBox(tr("Tox ID"), this);
QLabel* toxIdLabel = new QLabel(tr("Your Tox ID"), this);
toxID = new QLineEdit(this);
toxID->setReadOnly(true);
QVBoxLayout* toxLayout = new QVBoxLayout();
toxLayout->addWidget(toxIdLabel);
toxLayout->addWidget(toxID);
toxGroup->setLayout(toxLayout);
QVBoxLayout *mainLayout = new QVBoxLayout();
mainLayout->setSpacing(30);
mainLayout->addWidget(publicGroup);
mainLayout->addWidget(toxGroup);
mainLayout->addStretch(1);
setLayout(mainLayout);
}
QLineEdit* userName;
QLineEdit* statusMessage;
QLineEdit* toxID;
};
class PrivacyPage : public QWidget
{
public:
PrivacyPage(QWidget* parent = 0) :
QWidget(parent)
{}
};
class AVPage : public QWidget
{
Q_OBJECT
public:
AVPage(SettingsDialog* parent = 0) :
QWidget(parent)
{
QGroupBox *group = new QGroupBox(tr("Video Settings"), this);
camView = new SelfCamView(parent->getWidget()->getCamera());
camView->hide(); // hide by default
testVideo = new QPushButton(tr("Show video preview","On a button"));
connect(testVideo, SIGNAL(clicked()), this, SLOT(onTestVideoPressed()));
QVBoxLayout *vLayout = new QVBoxLayout();
vLayout->addWidget(testVideo);
vLayout->addWidget(camView);
group->setLayout(vLayout);
QVBoxLayout *mainLayout = new QVBoxLayout();
mainLayout->addWidget(group);
mainLayout->addStretch(1);
setLayout(mainLayout);
}
~AVPage()
{
delete camView;
}
void showTestVideo()
{
testVideo->setText(tr("Hide video preview","On a button"));
camView->show();
}
void closeTestVideo()
{
testVideo->setText(tr("Show video preview","On a button"));
camView->close();
}
QPushButton* testVideo;
SelfCamView* camView;
public slots:
void onTestVideoPressed()
{
if (camView->isVisible()) {
closeTestVideo();
} else {
showTestVideo();
}
}
};
// allows Q_OBJECT macro inside cpp
#include "settingsdialog.moc"
// =======================================
// settings dialog
//========================================
SettingsDialog::SettingsDialog(Widget *parent) :
QDialog(parent),
widget(parent)
{
createPages();
createButtons();
createConnections();
createLayout();
setWindowTitle(tr("qTox Settings"));
}
void SettingsDialog::createPages()
{
generalPage = new GeneralPage(this);
identityPage = new IdentityPage(this);
privacyPage = new PrivacyPage(this);
avPage = new AVPage(this);
contentsWidget = new QListWidget;
contentsWidget->setViewMode(QListView::IconMode);
contentsWidget->setIconSize(QSize(100, 73));
contentsWidget->setMovement(QListView::Static);
contentsWidget->setMaximumWidth(110);
contentsWidget->setMinimumWidth(110);
contentsWidget->setSpacing(0);
contentsWidget->setFlow(QListView::TopToBottom);
pagesWidget = new QStackedWidget;
pagesWidget->addWidget(generalPage);
pagesWidget->addWidget(identityPage);
pagesWidget->addWidget(privacyPage);
pagesWidget->addWidget(avPage);
QListWidgetItem *generalButton = new QListWidgetItem(contentsWidget);
generalButton->setIcon(QIcon(":/img/settings/general.png"));
generalButton->setText(tr("General"));
generalButton->setTextAlignment(Qt::AlignHCenter);
generalButton->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
QListWidgetItem *identity = new QListWidgetItem(contentsWidget);
identity->setIcon(QIcon(":/img/settings/identity.png"));
identity->setText(tr("Identity"));
identity->setTextAlignment(Qt::AlignHCenter);
identity->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
QListWidgetItem *privacy = new QListWidgetItem(contentsWidget);
privacy->setIcon(QIcon(":/img/settings/privacy.png"));
privacy->setText(tr("Privacy"));
privacy->setTextAlignment(Qt::AlignHCenter);
privacy->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
QListWidgetItem *av = new QListWidgetItem(contentsWidget);
av->setIcon(QIcon(":/img/settings/av.png"));
av->setText(tr("Audio/Video"));
av->setTextAlignment(Qt::AlignHCenter);
av->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
contentsWidget->setCurrentRow(0);
}
void SettingsDialog::createButtons()
{
okButton = new QPushButton(tr("Ok"), this);
cancelButton = new QPushButton(tr("Cancel"), this);
applyButton = new QPushButton(tr("Apply"), this);
}
void SettingsDialog::createConnections()
{
connect(okButton, SIGNAL(clicked()), this, SLOT(okPressed()));
connect(cancelButton, SIGNAL(clicked()), this, SLOT(close()));
connect(applyButton, SIGNAL(clicked()), this, SLOT(applyPressed()));
connect(
contentsWidget,
SIGNAL(currentItemChanged(QListWidgetItem*,QListWidgetItem*)),
this,
SLOT(changePage(QListWidgetItem*,QListWidgetItem*))
);
}
void SettingsDialog::createLayout()
{
setMinimumSize(800, 500);
QHBoxLayout *buttonsLayout = new QHBoxLayout();
buttonsLayout->addStretch(1);
buttonsLayout->addWidget(okButton);
buttonsLayout->addWidget(cancelButton);
buttonsLayout->addWidget(applyButton);
QHBoxLayout *hLayout = new QHBoxLayout();
hLayout->addWidget(contentsWidget);
hLayout->addWidget(pagesWidget, 1);
QVBoxLayout *mainLayout = new QVBoxLayout();
mainLayout->addLayout(hLayout);
mainLayout->addLayout(buttonsLayout);
setLayout(mainLayout);
}
void SettingsDialog::changePage(QListWidgetItem *current, QListWidgetItem *previous)
{
if (!current) {
current = previous;
}
pagesWidget->setCurrentIndex(contentsWidget->row(current));
}
void SettingsDialog::okPressed()
{
writeConfig();
close();
}
void SettingsDialog::cancelPressed()
{
close();
}
void SettingsDialog::applyPressed()
{
writeConfig();
}
void SettingsDialog::readConfig()
{
Settings& settings = Settings::getInstance();
Core* core = widget->getCore();
generalPage->enableIPv6->setChecked(settings.getEnableIPv6());
generalPage->useTranslations->setChecked(settings.getUseTranslations());
generalPage->makeToxPortable->setChecked(settings.getMakeToxPortable());
identityPage->userName->setText(core->getUsername());
identityPage->statusMessage->setText(core->getStatusMessage());
identityPage->toxID->setText(core->getSelfId().toString());
}
void SettingsDialog::writeConfig()
{
Settings& settings = Settings::getInstance();
Core* core = widget->getCore();
// only save settings if something changed
bool saveSettings = false;
if (settings.getEnableIPv6() != generalPage->enableIPv6->isChecked()) {
settings.setEnableIPv6(generalPage->enableIPv6->isChecked());
saveSettings = true;
}
if (settings.getUseTranslations() != generalPage->useTranslations->isChecked()) {
settings.setUseTranslations(generalPage->useTranslations->isChecked());
saveSettings = true;
}
if (settings.getMakeToxPortable() != generalPage->makeToxPortable->isChecked()) {
settings.setMakeToxPortable(generalPage->makeToxPortable->isChecked());
saveSettings = true;
}
if (settings.getSmileyPack() != generalPage->smileyPack->currentData().toString()) {
settings.setSmileyPack(generalPage->smileyPack->currentData().toString());
saveSettings = true;
}
if (saveSettings) {
settings.save();
}
// changing core settings will automatically save them
QString userName = identityPage->userName->text();
if (core->getUsername() != userName) {
core->setUsername(userName);
}
QString statusMessage = identityPage->statusMessage->text();
if (core->getStatusMessage() != statusMessage) {
core->setStatusMessage(statusMessage);
}
}
Widget* SettingsDialog::getWidget()
{
return widget;
}
void SettingsDialog::closeEvent(QCloseEvent* e){
avPage->closeTestVideo();
QDialog::closeEvent(e);
}

View File

@ -1,64 +0,0 @@
#ifndef SETTINGSDIALOG_H
#define SETTINGSDIALOG_H
#include <QWidget>
#include <QDialog>
class Widget;
class SelfCamView;
class Camera;
class GeneralPage;
class IdentityPage;
class PrivacyPage;
class AVPage;
class QListWidget;
class QListWidgetItem;
class QStackedWidget;
class QPushButton;
class QCheckBox;
class QLineEdit;
// =======================================
// settings dialog
//========================================
class SettingsDialog : public QDialog
{
Q_OBJECT
public:
explicit SettingsDialog(Widget *parent);
void readConfig();
void writeConfig();
Widget* getWidget();
void closeEvent(QCloseEvent *);
public slots:
void changePage(QListWidgetItem *current, QListWidgetItem *previous);
void okPressed();
void cancelPressed();
void applyPressed();
private:
void createPages();
void createButtons();
void createConnections();
void createLayout();
Widget* widget;
// pages
GeneralPage* generalPage;
IdentityPage* identityPage;
PrivacyPage* privacyPage;
AVPage* avPage;
QListWidget* contentsWidget;
QStackedWidget* pagesWidget;
// buttons
QPushButton* okButton;
QPushButton* cancelButton;
QPushButton* applyButton;
};
#endif // SETTINGSDIALOG_H

View File

@ -31,7 +31,6 @@
#include "widget/friendlistwidget.h"
#include "camera.h"
#include "widget/form/chatform.h"
#include "widget/settingsdialog.h"
#include "widget/maskablepixmapwidget.h"
#include <QMessageBox>
#include <QDebug>
@ -102,7 +101,7 @@ Widget::Widget(QWidget *parent)
Style::repolish(ui->statusButton);
camera = new Camera;
settingsDialog = new SettingsDialog(this);
settingsWidget = new SettingsWidget(camera);
// Disable some widgets until we're connected to the DHT
ui->statusButton->setEnabled(false);
@ -159,6 +158,8 @@ Widget::Widget(QWidget *parent)
connect(ui->statusLabel, SIGNAL(textChanged(QString,QString)), this, SLOT(onStatusMessageChanged(QString,QString)));
connect(profilePicture, SIGNAL(clicked()), this, SLOT(onAvatarClicked()));
connect(setStatusOnline, SIGNAL(triggered()), this, SLOT(setStatusOnline()));
// connect(settingsWidget->getIdentityForm(), &IdentityForm::userNameChanged, Core::getInstance(), &Core::setUsername);
// connect(settingsWidget->getIdentityForm(), &IdentityForm::statusMessageChanged, Core::getInstance(), &Core::setStatusMessage);
connect(setStatusAway, SIGNAL(triggered()), this, SLOT(setStatusAway()));
connect(setStatusBusy, SIGNAL(triggered()), this, SLOT(setStatusBusy()));
connect(&friendForm, SIGNAL(friendRequested(QString,QString)), this, SIGNAL(friendRequested(QString,QString)));
@ -171,12 +172,12 @@ Widget::Widget(QWidget *parent)
Widget::~Widget()
{
core->saveConfiguration();
instance = nullptr;
coreThread->exit();
coreThread->wait(500); // In case of deadlock (can happen with QtAudio/PA bugs)
if (!coreThread->isFinished())
coreThread->terminate();
delete core;
delete settingsWidget;
for (Friend* f : FriendList::friendList)
delete f;
@ -185,6 +186,7 @@ Widget::~Widget()
delete g;
GroupList::groupList.clear();
delete ui;
instance = nullptr;
}
Widget* Widget::getInstance()
@ -330,8 +332,9 @@ void Widget::onTransferClicked()
void Widget::onSettingsClicked()
{
settingsDialog->readConfig();
settingsDialog->show();
hideMainForms();
settingsWidget->show(*ui);
activeChatroomWidget = nullptr;
}
void Widget::hideMainForms()
@ -359,6 +362,7 @@ void Widget::setUsername(const QString& username)
{
ui->nameLabel->setText(username);
ui->nameLabel->setToolTip(username); // for overlength names
settingsWidget->getIdentityForm()->setUserName(username);
}
void Widget::onStatusMessageChanged(const QString& newStatusMessage, const QString& oldStatusMessage)
@ -372,6 +376,7 @@ void Widget::setStatusMessage(const QString &statusMessage)
{
ui->statusLabel->setText(statusMessage);
ui->statusLabel->setToolTip(statusMessage); // for overlength messsages
settingsWidget->getIdentityForm()->setStatusMessage(statusMessage);
}
void Widget::addFriend(int friendId, const QString &userId)

View File

@ -19,6 +19,8 @@
#include <QMainWindow>
#include "widget/form/addfriendform.h"
#include "widget/form/settingswidget.h"
#include "widget/form/settings/identityform.h"
#include "widget/form/filesform.h"
#include "corestructs.h"
@ -37,7 +39,6 @@ class QMenu;
class Core;
class Camera;
class FriendListWidget;
class SettingsDialog;
class MaskablePixmapWidget;
class Widget : public QMainWindow
@ -115,8 +116,8 @@ private:
Core* core;
QThread* coreThread;
AddFriendForm friendForm;
SettingsWidget* settingsWidget;
FilesForm filesForm;
SettingsDialog* settingsDialog;
static Widget* instance;
GenericChatroomWidget* activeChatroomWidget;
FriendListWidget* contactListWidget;