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

new settings infrastructure done, though there's a double free or something in ~Widget()

This commit is contained in:
bill 2014-09-15 05:45:59 -05:00 committed by Tux3 / Mlkj / !Lev.uXFMLA
parent e55f15725e
commit 5ec79fc260
12 changed files with 423 additions and 23 deletions

View File

@ -82,6 +82,11 @@ 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 \
@ -119,6 +124,10 @@ SOURCES += \
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 \

View File

@ -0,0 +1,26 @@
/*
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"
AVForm::AVForm()
{
prep();
}
AVForm::~AVForm()
{
}

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 AVFORM_H
#define AVFORM_H
#include "genericsettings.h"
class AVForm : public GenericForm
{
Q_OBJECT
public:
AVForm();
~AVForm();
private:
};
#endif

View File

@ -0,0 +1,46 @@
/*
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 "generalform.h"
#include "widget/form/settingswidget.h"
GeneralForm::GeneralForm()
{
prep();
group = new QGroupBox(tr("General Settings"));
enableIPv6 = new QCheckBox();
enableIPv6->setText(tr("Enable IPv6 (recommended)","Text on a checkbox to enable IPv6"));
useTranslations = new QCheckBox();
useTranslations->setText(tr("Use translations","Text on a checkbox to enable translations"));
makeToxPortable = new QCheckBox();
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);
label.setText(tr("General Settings"));
headLayout.addWidget(&label);
layout.addWidget(group);
}
GeneralForm::~GeneralForm()
{
}

View File

@ -0,0 +1,41 @@
/*
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 <QGroupBox>
#include <QCheckBox>
#include <QLabel>
class GeneralForm : public GenericForm
{
Q_OBJECT
public:
GeneralForm();
~GeneralForm();
private:
QGroupBox *group;
QCheckBox* enableIPv6;
QCheckBox* useTranslations;
QCheckBox* makeToxPortable;
QLabel label;
};
#endif

View File

@ -0,0 +1,46 @@
/*
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 <QObject>
#include <QVBoxLayout>
#include "widget/form/settingswidget.h"
class GenericForm : public QObject
{
Q_OBJECT
public:
virtual void show(SettingsWidget& sw)
{
sw.body->layout()->addWidget(&body);
body.show();
sw.head->layout()->addWidget(&head);
head.show();
}
protected:
QVBoxLayout layout, headLayout;
QWidget head, body;
void prep() // call in subclass constructor
{
head.setLayout(&headLayout);
body.setLayout(&layout);
}
};
#endif

View File

@ -0,0 +1,38 @@
/*
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 "identityform.h"
#include "widget/form/settingswidget.h"
#include <QLabel>
#include <QLineEdit>
IdentityForm::IdentityForm()
{
prep();
toxGroup = new QGroupBox(tr("Tox ID"));
QLabel* toxIdLabel = new QLabel(tr("Your Tox ID"));
QLineEdit* toxID = new QLineEdit();
toxID->setReadOnly(true);
QVBoxLayout* toxLayout = new QVBoxLayout();
toxLayout->addWidget(toxIdLabel);
toxLayout->addWidget(toxID);
toxGroup->setLayout(toxLayout);
layout.addWidget(toxGroup);
}
IdentityForm::~IdentityForm()
{
}

View File

@ -0,0 +1,34 @@
/*
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>
class IdentityForm : public GenericForm
{
Q_OBJECT
public:
IdentityForm();
~IdentityForm();
private:
QGroupBox* toxGroup;
};
#endif

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()
{
prep();
}
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

@ -17,21 +17,41 @@
#include "settingswidget.h"
#include "widget/widget.h"
#include "ui_mainwindow.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"
SettingsWidget::SettingsWidget()
: QWidget()
{
_main = new QWidget();
generalForm = new GeneralForm();
identityForm = new IdentityForm();
privacyForm = new PrivacyForm();
avForm = new AVForm();
main = new QWidget();
body = new QWidget();
head = new QWidget();
foot = new QWidget();
head->setLayout(new QVBoxLayout());
body->setLayout(new QVBoxLayout());
prepButtons();
foot->setLayout(iconsLayout);
_mainLayout = new QVBoxLayout(_main);
_mainLayout->addWidget(main);
_mainLayout->addWidget(foot);
mainLayout = new QVBoxLayout(main);
mainLayout->addWidget(body);
mainLayout->addWidget(foot);
// something something foot size
_main->setLayout(_mainLayout);
main->setLayout(mainLayout);
connect(generalButton, &QPushButton::clicked, this, &SettingsWidget::onGeneralClicked);
connect(identityButton, &QPushButton::clicked, this, &SettingsWidget::onIdentityClicked);
connect(privacyButton, &QPushButton::clicked, this, &SettingsWidget::onPrivacyClicked);
connect(avButton, &QPushButton::clicked, this, &SettingsWidget::onAVClicked);
active = generalForm;
}
SettingsWidget::~SettingsWidget()
@ -40,12 +60,50 @@ SettingsWidget::~SettingsWidget()
void SettingsWidget::show(Ui::MainWindow& ui)
{
ui.mainContent->layout()->addWidget(_main);
active->show(*this);
ui.mainContent->layout()->addWidget(main);
ui.mainHead->layout()->addWidget(head);
_main->show();
main->show();
head->show();
}
void SettingsWidget::onGeneralClicked()
{
hideSettingsForms();
active = generalForm;
generalForm->show(*this);
}
void SettingsWidget::onIdentityClicked()
{
hideSettingsForms();
active = identityForm;
identityForm->show(*this);
}
void SettingsWidget::onPrivacyClicked()
{
hideSettingsForms();
active = privacyForm;
privacyForm->show(*this);
}
void SettingsWidget::onAVClicked()
{
hideSettingsForms();
active = avForm;
avForm->show(*this);
}
void SettingsWidget::hideSettingsForms()
{
QLayoutItem *item;
while ((item = head->layout()->takeAt(0)) != 0)
item->widget()->hide();
while ((item = body->layout()->takeAt(0)) != 0)
item->widget()->hide();
}
void SettingsWidget::prepButtons()
{
// this crap is copied from ui_mainwindow.h... there's no easy way around

View File

@ -19,11 +19,12 @@
#include <QHBoxLayout>
#include <QPushButton>
#include <QObject>
#include "widget/croppinglabel.h"
namespace Ui {class MainWindow;}
class QString;
class GenericForm;
class GeneralForm;
class IdentityForm;
class PrivacyForm;
class AVForm;
namespace Ui {class MainWindow;};
class SettingsWidget : public QWidget
{
@ -34,29 +35,37 @@ public:
void show(Ui::MainWindow &ui);
QWidget *head, *body; // keep the others private
public slots:
//void setFriendAddress(const QString& friendAddress);
private slots:
void onGeneralClicked();
void onIdentityClicked();
void onPrivacyClicked();
void onAVClicked();
private:
QWidget *_main, *main, *head, *foot;
// _main consists of main+foot
QVBoxLayout *_mainLayout;
QWidget *main, *foot;
// main consists of body+foot for Ui::MainWindow
QVBoxLayout *mainLayout;
GenericForm* active;
GeneralForm* generalForm;
IdentityForm* identityForm;
PrivacyForm* privacyForm;
AVForm* avForm;
void hideSettingsForms();
// the code pertaining to the icons is mostly copied from ui_mainwindow.h
QHBoxLayout *iconsLayout;
QPushButton *generalButton;
QPushButton *identityButton;
QPushButton *privacyButton;
QPushButton *avButton;
// now the actual pages and stuff
// ...
void prepButtons(); // just so I can move the crap to the bottom of the file
public:
};
#endif // SETTINGSFORM_H
#endif // SETTINGSWIDGET_H