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

Multi-window: Translate all dialogs correctly, don't allow remove friend on dialogs

This commit is contained in:
TheSpiritXIII 2015-07-02 14:38:18 -04:00 committed by tux3
parent 6a5fb9f518
commit f825985856
6 changed files with 81 additions and 18 deletions

View File

@ -33,6 +33,7 @@
#include "src/core/core.h"
#include "src/widget/friendlistlayout.h"
#include "src/widget/form/settingswidget.h"
#include "src/widget/translator.h"
#include <QBoxLayout>
#include <QSplitter>
#include <QGuiApplication>
@ -120,6 +121,8 @@ ContentDialog::ContentDialog(SettingsWidget* settingsWidget, QWidget* parent)
new QShortcut(Qt::CTRL + Qt::Key_PageDown, this, SLOT(nextContact()));
connect(Core::getInstance(), &Core::usernameSet, this, &ContentDialog::updateTitleUsername);
Translator::registerHandler(std::bind(&ContentDialog::retranslateUi, this), this);
}
ContentDialog::~ContentDialog()
@ -150,6 +153,8 @@ ContentDialog::~ContentDialog()
}
++groupIt;
}
Translator::unregister(this);
}
FriendWidget* ContentDialog::addFriend(int friendId, QString id)
@ -573,6 +578,11 @@ void ContentDialog::onGroupchatPositionChanged(bool top)
friendLayout->insertLayout(1, groupLayout.getLayout());
}
void ContentDialog::retranslateUi()
{
updateTitleUsername(Core::getInstance()->getUsername());
}
void ContentDialog::saveDialogGeometry()
{
Settings::getInstance().setDialogGeometry(saveGeometry());

View File

@ -26,6 +26,7 @@
#include "src/widget/genericchatitemlayout.h"
template <typename K, typename V> class QHash;
template <typename T> class QSet;
class QSplitter;
class QVBoxLayout;
@ -86,6 +87,7 @@ private slots:
void onGroupchatPositionChanged(bool top);
private:
void retranslateUi();
void saveDialogGeometry();
void saveSplitterState();
QLayout* nextLayout(QLayout* layout, bool forward) const;

View File

@ -40,7 +40,7 @@
<x>0</x>
<y>0</y>
<width>639</width>
<height>1221</height>
<height>1388</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_4" stretch="0,0,0,1">
@ -387,7 +387,7 @@ instead of system taskbar.</string>
<bool>false</bool>
</property>
<property name="text">
<string>Don't group chat wndows.</string>
<string>Don't group chat windows.</string>
</property>
</widget>
</item>

View File

@ -147,7 +147,10 @@ void FriendWidget::contextMenuEvent(QContextMenuEvent * event)
autoAccept->setChecked(!dir.isEmpty());
menu.addSeparator();
QAction* removeFriendAction = menu.addAction(tr("Remove friend", "Menu to remove the friend from our friendlist"));
QAction* removeFriendAction = nullptr;
if (contentDialog == nullptr || !contentDialog->hasFriendWidget(friendId, this))
removeFriendAction = menu.addAction(tr("Remove friend", "Menu to remove the friend from our friendlist"));
QAction* selectedItem = menu.exec(pos);

View File

@ -592,7 +592,7 @@ void Widget::onSeparateWindowChanged(bool separate, bool clicked)
if (clicked)
{
ContentLayout* contentLayout = createContentDialog(tr("Settings"));
ContentLayout* contentLayout = createContentDialog((SettingDialog));
contentLayout->parentWidget()->resize(size);
contentLayout->parentWidget()->move(pos);
settingsWidget->show(contentLayout);
@ -628,7 +628,7 @@ void Widget::onAddClicked()
{
if (!addFriendForm->isShown())
{
addFriendForm->show(createContentDialog(tr("Add friend")));
addFriendForm->show(createContentDialog(AddDialog));
setActiveToolMenuButton(Widget::None);
}
}
@ -636,7 +636,7 @@ void Widget::onAddClicked()
{
hideMainForms(nullptr);
addFriendForm->show(contentLayout);
setWindowTitle(tr("Add friend"));
setWindowTitle(fromDialogType(AddDialog));
setActiveToolMenuButton(Widget::AddButton);
}
}
@ -652,7 +652,7 @@ void Widget::onTransferClicked()
{
if (!filesForm->isShown())
{
filesForm->show(createContentDialog(tr("File transfers")));
filesForm->show(createContentDialog(TransferDialog));
setActiveToolMenuButton(Widget::None);
}
}
@ -660,7 +660,7 @@ void Widget::onTransferClicked()
{
hideMainForms(nullptr);
filesForm->show(contentLayout);
setWindowTitle(tr("File transfers"));
setWindowTitle(fromDialogType(TransferDialog));
setActiveToolMenuButton(Widget::TransferButton);
}
}
@ -741,7 +741,7 @@ void Widget::onSettingsClicked()
{
if (!settingsWidget->isShown())
{
settingsWidget->show(createContentDialog(tr("Settings")));
settingsWidget->show(createContentDialog(SettingDialog));
setActiveToolMenuButton(Widget::None);
}
}
@ -749,7 +749,7 @@ void Widget::onSettingsClicked()
{
hideMainForms(nullptr);
settingsWidget->show(contentLayout);
setWindowTitle(tr("Settings"));
setWindowTitle(fromDialogType(SettingDialog));
setActiveToolMenuButton(Widget::SettingButton);
}
}
@ -760,7 +760,7 @@ void Widget::showProfile() // onAvatarClicked, onUsernameClicked
{
if (!profileForm->isShown())
{
profileForm->show(createContentDialog(tr("Profile")));
profileForm->show(createContentDialog(ProfileDialog));
setActiveToolMenuButton(Widget::None);
}
}
@ -768,7 +768,7 @@ void Widget::showProfile() // onAvatarClicked, onUsernameClicked
{
hideMainForms(nullptr);
profileForm->show(contentLayout);
setWindowTitle(tr("Profile"));
setWindowTitle(fromDialogType(ProfileDialog));
setActiveToolMenuButton(Widget::None);
}
}
@ -1141,6 +1141,23 @@ bool Widget::newGroupMessageAlert(int groupId)
return newMessageAlert(currentWindow, hasActive);
}
QString Widget::fromDialogType(DialogType type)
{
switch (type)
{
case AddDialog:
return tr("Add friend");
case TransferDialog:
return tr("File transfers");
case SettingDialog:
return tr("Settings");
case ProfileDialog:
return tr("Profile");
default:
return QString();
}
}
bool Widget::newMessageAlert(QWidget* currentWindow, bool isActive)
{
bool inactiveWindow = isMinimized() || !currentWindow->isActiveWindow();
@ -1277,15 +1294,32 @@ ContentDialog* Widget::createContentDialog() const
return new ContentDialog(settingsWidget);
}
ContentLayout* Widget::createContentDialog(const QString &title) const
ContentLayout* Widget::createContentDialog(DialogType type) const
{
class Dialog : public QDialog
{
public:
Dialog()
Dialog(DialogType type)
: QDialog()
, type(type)
{
restoreGeometry(Settings::getInstance().getDialogSettingsGeometry());
Translator::registerHandler(std::bind(&Dialog::retranslateUi, this), this);
retranslateUi();
connect(Core::getInstance(), &Core::usernameSet, this, &Dialog::retranslateUi);
}
~Dialog()
{
Translator::unregister(this);
}
public slots:
void retranslateUi()
{
setWindowTitle(Core::getInstance()->getUsername() + QStringLiteral(" - ") + Widget::fromDialogType(type));
}
protected:
@ -1300,9 +1334,12 @@ ContentLayout* Widget::createContentDialog(const QString &title) const
Settings::getInstance().setDialogSettingsGeometry(saveGeometry());
QDialog::moveEvent(event);
}
private:
DialogType type;
};
QDialog* dialog = new Dialog();
QDialog* dialog = new Dialog(type);
dialog->setAttribute(Qt::WA_DeleteOnClose);
ContentLayout* contentLayoutDialog = new ContentLayout(dialog);
@ -1312,7 +1349,6 @@ ContentLayout* Widget::createContentDialog(const QString &title) const
dialog->layout()->setSpacing(0);
dialog->setMinimumSize(720, 400);
dialog->setAttribute(Qt::WA_DeleteOnClose);
dialog->setWindowTitle(title);
dialog->show();
return contentLayoutDialog;
@ -1971,7 +2007,9 @@ void Widget::retranslateUi()
statusOnline->setText(tr("Online", "Button to set your status to 'Online'"));
statusAway->setText(tr("Away", "Button to set your status to 'Away'"));
statusBusy->setText(tr("Busy", "Button to set your status to 'Busy'"));
//setWindowTitle(tr("Settings"));
if (!Settings::getInstance().getSeparateWindow())
setWindowTitle(fromDialogType(SettingDialog));
}
#ifdef Q_OS_MAC

View File

@ -72,8 +72,18 @@ public:
bool getIsWindowMinimized();
void updateIcons();
void clearContactsList();
enum DialogType
{
AddDialog,
TransferDialog,
SettingDialog,
ProfileDialog
};
static QString fromDialogType(DialogType type);
ContentDialog* createContentDialog() const;
ContentLayout* createContentDialog(const QString& title) const;
ContentLayout* createContentDialog(DialogType type) const;
static void confirmExecutableOpen(const QFileInfo file);