Commit fc33a49c authored by Andreas Traczyk's avatar Andreas Traczyk

main window: hide/show top level widgets when navigating

- removes the effects of a widget's constraints when it is present
  in the navstack, but not the current index

- all widgets in the navstack now have a QWidget with a grid layout
  as the top level

- regulates the size of the main window

Change-Id: I6b0726d9777be1b33fdf164ce9dd3db5ec917ec1
parent ec8e9a5d
......@@ -195,6 +195,8 @@ CallWidget::CallWidget(QWidget* parent) :
// hide the call stack
ui->callStackWidget->hide();
ui->containerWidget->setVisible(false);
}
CallWidget::~CallWidget()
......@@ -203,6 +205,19 @@ CallWidget::~CallWidget()
delete menu_;
}
void
CallWidget::navigated(bool to)
{
ui->containerWidget->setVisible(to);
if (to) {
updateSmartList();
connectConversationModel();
} else {
QObject::disconnect(smartlistSelectionConnection_);
smartListModel_.reset(nullptr);
}
}
int
CallWidget::getLeftPanelWidth()
{
......@@ -1072,7 +1087,7 @@ void
CallWidget::updateSmartList()
{
auto& currentAccountInfo = LRCInstance::getCurrentAccountInfo();
smartListModel_.reset(new SmartListModel(currentAccountInfo, this->parent()));
smartListModel_.reset(new SmartListModel(currentAccountInfo, this));
ui->smartList->setModel(smartListModel_.get());
ui->smartList->setItemDelegate(new ConversationItemDelegate());
......
......@@ -66,6 +66,9 @@ public:
int getLeftPanelWidth();
// NavWidget
virtual void navigated(bool to);
public slots:
void on_ringContactLineEdit_returnPressed();
......
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -21,6 +21,8 @@
#include "ui_mainwindow.h"
#include <QDesktopWidget>
#include <QWindow>
#include <QScreen>
#include "media/text.h"
#include "media/textrecording.h"
......@@ -47,23 +49,21 @@ MainWindow::MainWindow(QWidget* parent) :
{
ui->setupUi(this);
connect(ui->wizardwidget, &WizardWidget::NavigationRequested,
[this](ScreenEnum scr) {
int index = scr;
if (scr == ScreenEnum::SetttingsScreen) {
index = addSettingsWidget();
}
Utils::setStackWidget(ui->navStack, ui->navStack->widget(index));
});
setMinimumSize(mainWindowMinWidth, mainWindowMinHeight);
setMaximumSize(QtMaxDimension, QtMaxDimension);
connect(ui->callwidget, &CallWidget::NavigationRequested,
[this](ScreenEnum scr) {
int index = scr;
if (scr == ScreenEnum::SetttingsScreen) {
index = addSettingsWidget();
}
Utils::setStackWidget(ui->navStack, ui->navStack->widget(index));
});
for (int i = 0; i < ui->navStack->count(); ++i) {
if (auto navWidget = dynamic_cast<NavWidget*>(ui->navStack->widget(i))) {
connect(navWidget, &NavWidget::NavigationRequested,
[this](ScreenEnum scr) {
Utils::setStackWidget(ui->navStack, ui->navStack->widget(scr));
});
}
}
connect(ui->navStack, SIGNAL(currentChanged(int)),
this, SLOT(slotCurrentChanged(int)),
Qt::QueuedConnection);
QIcon icon(":images/jami.png");
......@@ -77,12 +77,7 @@ MainWindow::MainWindow(QWidget* parent) :
auto configAction = new QAction(tr("Settings"), this);
connect(configAction, &QAction::triggered,
[this]() {
if (auto settingsWidget = getSettingsWidget()) {
Utils::setStackWidget(ui->navStack, settingsWidget);
} else {
auto index = addSettingsWidget();
Utils::setStackWidget(ui->navStack, ui->navStack->widget(index));
}
Utils::setStackWidget(ui->navStack, ui->settingswidget);
setWindowState(Qt::WindowActive);
});
menu->addAction(configAction);
......@@ -112,8 +107,6 @@ MainWindow::MainWindow(QWidget* parent) :
}
#endif
readSettingsFromRegistry();
win_sparkle_set_appcast_url("http://dl.jami.net/windows/winsparkle-ring.xml");
win_sparkle_set_app_details(L"Savoir-faire Linux", L"Jami", QString(VERSION_STRING).toStdWString().c_str());
win_sparkle_set_shutdown_request_callback([]() {QCoreApplication::exit();});
......@@ -137,21 +130,26 @@ MainWindow::MainWindow(QWidget* parent) :
AccountModel::instance().slotConnectivityChanged();
});
auto flags_ = windowFlags();
auto accountList = LRCInstance::accountModel().getAccountList();
ScreenEnum startScreen;
if (accountList.size()) {
for (const auto& accountId : accountList) {
auto& accountInfo = LRCInstance::accountModel().getAccountInfo(accountId);
if (accountInfo.profileInfo.type == lrc::api::profile::Type::RING) {
if (accountInfo.status == lrc::api::account::Status::ERROR_NEED_MIGRATION) {
WizardDialog dlg(WizardDialog::MIGRATION);
dlg.exec();
}
}
}
Utils::setStackWidget(ui->navStack, ui->navStack->widget(ScreenEnum::CallScreen));
readSettingsFromRegistry();
startScreen = ScreenEnum::CallScreen;
} else {
Utils::setStackWidget(ui->navStack, ui->navStack->widget(ScreenEnum::WizardScreen));
startScreen = ScreenEnum::WizardScreen;
}
Utils::setStackWidget(ui->navStack, ui->navStack->widget(startScreen));
if (startScreen == ScreenEnum::WizardScreen) {
setWindowSize(startScreen);
}
if (auto navWidget = dynamic_cast<NavWidget*>(ui->navStack->widget(startScreen))) {
navWidget->navigated(true);
}
lastScr_ = startScreen;
}
MainWindow::~MainWindow()
......@@ -159,39 +157,27 @@ MainWindow::~MainWindow()
delete ui;
}
int
MainWindow::addSettingsWidget()
void
MainWindow::slotCurrentChanged(int index)
{
int index = -1;
if (ui->navStack->count() < ScreenEnum::SetttingsScreen + 1) {
auto settingsWidget = new SettingsWidget(this);
settingsWidget->updateSettings(ui->callwidget->getLeftPanelWidth());
index = ui->navStack->addWidget(settingsWidget);
connect(settingsWidget, &SettingsWidget::NavigationRequested,
[this](ScreenEnum scr) {
Utils::setStackWidget(ui->navStack, ui->navStack->widget(scr));
removeSettingsWidget();
if (scr == ScreenEnum::CallScreen) {
ui->callwidget->update();
}
});
auto accountList = LRCInstance::accountModel().getAccountList();
auto firstUse =
(accountList.size() == 1 && lastScr_ == ScreenEnum::WizardScreen) ||
!accountList.size();
for (int i = 0; i < ui->navStack->count(); ++i) {
if (auto navWidget = dynamic_cast<NavWidget*>(ui->navStack->widget(i))) {
navWidget->navigated(index == i);
}
}
return index;
}
void
MainWindow::removeSettingsWidget()
{
if (auto settingsWidget = getSettingsWidget()) {
ui->navStack->removeWidget(settingsWidget);
settingsWidget->deleteLater();
auto scr = Utils::toEnum<ScreenEnum>(index);
if (scr == ScreenEnum::SetttingsScreen) {
ui->settingswidget->updateSettings(ui->callwidget->getLeftPanelWidth());
}
}
SettingsWidget*
MainWindow::getSettingsWidget()
{
return qobject_cast<SettingsWidget*>(ui->navStack->widget(ScreenEnum::SetttingsScreen));
setWindowSize(scr, firstUse);
lastScr_ = scr;
}
void
......@@ -263,12 +249,7 @@ MainWindow::createThumbBar()
settings->setIcon(icon);
settings->setDismissOnClick(true);
connect(settings, &QWinThumbnailToolButton::clicked, [this]() {
if (auto settingsWidget = getSettingsWidget()) {
Utils::setStackWidget(ui->navStack, settingsWidget);
} else {
auto index = addSettingsWidget();
Utils::setStackWidget(ui->navStack, ui->navStack->widget(index));
}
Utils::setStackWidget(ui->navStack, ui->settingswidget);
});
thumbbar->addButton(settings);
......@@ -312,3 +293,49 @@ MainWindow::readSettingsFromRegistry()
settings.setValue(SettingsKey::enableNotifications, true);
}
}
void
MainWindow::setWindowSize(ScreenEnum scr, bool firstUse)
{
auto screenNumber = qApp->desktop()->screenNumber();
QScreen* screen = qApp->screens().at(screenNumber);
auto accountList = LRCInstance::accountModel().getAccountList();
if (scr == ScreenEnum::WizardScreen && !accountList.size()) {
hide();
setFixedSize(wizardDialogWidth, wizardDialogHeight);
}
if (firstUse || !accountList.size()) {
setGeometry(
QStyle::alignedRect(
Qt::LeftToRight,
Qt::AlignCenter,
size(),
qApp->desktop()->screenGeometry(screenNumber)
)
);
windowHandle()->setScreen(screen);
if (scr == ScreenEnum::WizardScreen) {
setWindowFlags(Qt::Dialog);
setWindowFlags(windowFlags() & (~Qt::WindowContextHelpButtonHint));
adjustSize();
} else {
setWindowFlags(flags_);
}
updateGeometry();
update();
show();
}
}
void
MainWindow::show()
{
QMainWindow::show();
disconnect(screenChangedConnection_);
screenChangedConnection_ = connect(windowHandle(), &QWindow::screenChanged,
[this](QScreen* screen) {
adjustSize();
updateGeometry();
update();
});
}
......@@ -32,6 +32,12 @@
static constexpr char IDM_ABOUTBOX = 0x0010;
static constexpr uint32_t QtMaxDimension = 16777215;
static constexpr uint32_t mainWindowMinWidth = 1088;
static constexpr uint32_t mainWindowMinHeight = 600;
static constexpr uint32_t wizardDialogWidth = 512;
static constexpr uint32_t wizardDialogHeight = 512;
namespace Ui {
class MainWindow;
}
......@@ -48,6 +54,8 @@ public:
void createThumbBar();
bool init();
void show();
protected:
bool nativeEvent(const QByteArray& eventType, void* message, long* result);
void closeEvent(QCloseEvent* event);
......@@ -56,6 +64,7 @@ public slots:
void onRingEvent(const QString& uri);
private slots:
void slotCurrentChanged(int index);
void trayActivated(QSystemTrayIcon::ActivationReason reason);
void onIncomingCall(Call* call);
void switchNormalMaximize();
......@@ -65,11 +74,13 @@ private:
explicit MainWindow(QWidget* parent = 0);
~MainWindow();
void setWindowSize(ScreenEnum scr, bool firstUse = false);
ScreenEnum lastScr_;
Qt::WindowFlags flags_;
void readSettingsFromRegistry();
void removeSettingsWidget();
int addSettingsWidget();
SettingsWidget* getSettingsWidget();
Ui::MainWindow* ui;
QNetworkConfigurationManager netManager_;
QMetaObject::Connection screenChangedConnection_;
};
......@@ -465,6 +465,14 @@
<widget class="QStackedWidget" name="navStack">
<widget class="WizardWidget" name="wizardwidget"/>
<widget class="CallWidget" name="callwidget"/>
<widget class="SettingsWidget" name="settingswidget">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</widget>
</item>
</layout>
......@@ -484,6 +492,11 @@
<header>wizardwidget.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>SettingsWidget</class>
<extends>QWidget</extends>
<header>settingswidget.h</header>
</customwidget>
</customwidgets>
<resources>
<include location="ressources.qrc"/>
......
......@@ -36,8 +36,11 @@ public:
explicit NavWidget(QWidget* parent = 0);
~NavWidget();
virtual void navigated(bool to) = 0;
signals:
void NavigationRequested(ScreenEnum screen);
void BackRequested();
};
......@@ -130,7 +130,26 @@ SettingsWidget::SettingsWidget(QWidget* parent)
ui->advancedSettingsOffsetLabel->show();
setConnections();
auto accountList = LRCInstance::accountModel().getAccountList();
if (!accountList.size()) {
QMetaObject::Connection* toDisconnect = &accountAddedConnection_;
accountAddedConnection_ = connect(&LRCInstance::accountModel(),
&lrc::api::NewAccountModel::accountAdded,
[this, toDisconnect](const std::string& accountId) {
setConnections();
QObject::disconnect(*toDisconnect);
});
} else {
setConnections();
}
ui->containerWidget->setVisible(false);
}
void
SettingsWidget::navigated(bool to)
{
ui->containerWidget->setVisible(to);
}
void
......
......@@ -52,6 +52,9 @@ public:
~SettingsWidget();
void resize(int size);
// NavWidget
virtual void navigated(bool to);
public slots:
void updateSettings(int size);
......@@ -126,6 +129,8 @@ private:
QSettings* settings_;
QMetaObject::Connection accountAddedConnection_;
private slots:
void setNotificationsSlot(int state);
void checkForUpdateSlot();
......
This diff is collapsed.
......@@ -45,11 +45,6 @@ WizardWidget::WizardWidget(WizardMode wizardMode, AccountInfo* toBeMigrated, QWi
{
ui->setupUi(this);
Qt::WindowFlags flags = windowFlags();
flags = flags & (~Qt::WindowContextHelpButtonHint);
setWindowFlags(flags);
QPixmap logo(":/images/logo-jami-standard-coul.png");
ui->welcomeLogo->setPixmap(logo.scaledToHeight(65, Qt::SmoothTransformation));
......@@ -81,6 +76,8 @@ WizardWidget::WizardWidget(WizardMode wizardMode, AccountInfo* toBeMigrated, QWi
connect(&nameLookupTimer_, &QTimer::timeout, this, &WizardWidget::timeoutNameLookupTimer);
connect(ui->photoBooth, &PhotoboothWidget::photoTaken, this, &WizardWidget::on_photoTaken);
ui->avatarLabel->hide();
ui->containerWidget->setVisible(false);
}
WizardWidget::~WizardWidget()
......@@ -90,6 +87,13 @@ WizardWidget::~WizardWidget()
delete ui;
}
void
WizardWidget::navigated(bool to)
{
ui->containerWidget->setVisible(to);
Utils::setStackWidget(ui->stackedWidget, ui->welcomePage);
}
void
WizardWidget::processWizardInformations()
{
......
......@@ -52,6 +52,9 @@ public:
explicit WizardWidget(WizardMode wizardMode = WIZARD, AccountInfo* toBeMigrated = nullptr, QWidget* parent = 0);
~WizardWidget();
// NavWidget
virtual void navigated(bool to);
//UI Slots
private slots:
void on_existingPushButton_clicked();
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment