Commit c1ca2dfb authored by Olivier SOLDANO's avatar Olivier SOLDANO Committed by Andreas Traczyk

Navigation stack refactorisation

simplifies the mainwindow ui stacked widget
removes the progamatic construction and replaces it
with the designer QML.
Also factorises the code of slidepage in Utils.h for
a consistent page switching at all levels of UI.

Change-Id: I75ee29b0b93de63978262db4da04dc6c96e0942e
Reviewed-by: Andreas Traczyk's avatarAndreas Traczyk <andreas.traczyk@savoirfairelinux.com>
parent 9067c208
......@@ -44,7 +44,6 @@ SOURCES += main.cpp\
mainwindow.cpp \
callwidget.cpp \
configurationwidget.cpp \
navstack.cpp \
navwidget.cpp \
accountdetails.cpp \
aboutdialog.cpp \
......@@ -87,7 +86,6 @@ SOURCES += main.cpp\
HEADERS += mainwindow.h \
callwidget.h \
configurationwidget.h \
navstack.h \
navwidget.h \
accountdetails.h \
aboutdialog.h \
......
......@@ -161,7 +161,7 @@ CallWidget::CallWidget(QWidget* parent) :
connect(ui->searchBtn, SIGNAL(clicked(bool)), this, SLOT(searchBtnClicked()));
connect(ui->sendContactRequestWidget, &SendContactRequestWidget::sendCRclicked, [=]{slidePage(ui->messagingPage);});
connect(ui->sendContactRequestWidget, &SendContactRequestWidget::sendCRclicked, [=]{Utils::slidePage(ui->stackedWidget, ui->messagingPage);});
connect(ui->contactRequestWidget, &ContactRequestWidget::choiceMade, [this]() {
if (getSelectedAccount()->pendingContactRequestModel()->rowCount() == 0)
......@@ -597,7 +597,7 @@ CallWidget::smartListCurrentChanged(const QModelIndex &currentIdx, const QModelI
if (not currentIdx.isValid()) {
auto widget = ui->stackedWidget->currentWidget();
if (widget == ui->messagingPage || widget == ui->videoPage)
slidePage(ui->welcomePage);
Utils::slidePage(ui->stackedWidget, ui->welcomePage);
if(actualCall_)
setActualCall(nullptr);
return;
......@@ -634,7 +634,7 @@ CallWidget::contactReqListCurrentChanged(const QModelIndex &currentIdx, const QM
} else {
ui->contactRequestWidget->setCurrentContactRequest(QModelIndex());
if (ui->stackedWidget->currentWidget() == ui->contactRequestPage)
slidePage(ui->welcomePage);
Utils::slidePage(ui->stackedWidget, ui->welcomePage);
}
}
......@@ -746,7 +746,7 @@ CallWidget::selectedAccountChanged(const QModelIndex &current, const QModelIndex
if (ui->stackedWidget->currentWidget() != ui->videoPage &&
ui->stackedWidget->currentWidget() != ui->welcomePage) {
slidePage(ui->welcomePage);
Utils::slidePage(ui->stackedWidget, ui->welcomePage);
}
// We setup the ringIdLabel and the QRCode
......@@ -943,19 +943,6 @@ CallWidget::on_imBackButton_clicked()
backToWelcomePage();
}
void
CallWidget::slidePage(QWidget* widget, bool toRight)
{
short dir = (toRight ? -1 : 1);
ui->stackedWidget->setCurrentWidget(widget);
pageAnim_->setTargetObject(widget);
pageAnim_->setDuration(animDuration_);
pageAnim_->setStartValue(QPoint(widget->width() * dir, widget->y()));
pageAnim_->setEndValue(QPoint(widget->x(), widget->y()));
pageAnim_->setEasingCurve(QEasingCurve::OutQuad);
pageAnim_->start();
}
void
CallWidget::on_qrButton_toggled(bool checked)
{
......
......@@ -115,7 +115,6 @@ private:
QMenu* shareMenu_;
QMovie* miniSpinner_;
constexpr static int animDuration_ = 200; //msecs
constexpr static int qrSize_ = 200;
private:
......
......@@ -23,8 +23,6 @@
#include <QClipboard>
#include <QMenu>
#include "navstack.h"
#include "media/text.h"
#include "media/textrecording.h"
......
......@@ -34,12 +34,18 @@
#include "settingskey.h"
#include "winsparkle.h"
#include "callmodel.h"
#include "callwidget.h"
#include "utils.h"
MainWindow::MainWindow(QWidget* parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
connect(ui->callwidget, CallWidget::NavigationRequested,
[this](ScreenEnum scr){Utils::slidePage(ui->navStack, ui->navStack->widget(scr));});
connect(ui->configurationwidget, ConfigurationWidget::NavigationRequested,
[this](ScreenEnum scr){Utils::slidePage(ui->navStack, ui->navStack->widget(scr));});
QIcon icon(":images/ring.png");
......@@ -68,11 +74,6 @@ MainWindow::MainWindow(QWidget* parent) :
connect(&CallModel::instance(), SIGNAL(incomingCall(Call*)),
this, SLOT(onIncomingCall(Call*)));
navStack_ = new NavStack(ui->stackedWidgetView, this);
connect(configAction, &QAction::triggered, [this]() {
navStack_->onNavigationRequested(ScreenEnum::ConfScreen);
});
#ifdef Q_OS_WIN
HMENU sysMenu = ::GetSystemMenu((HWND) winId(), FALSE);
if (sysMenu != NULL) {
......@@ -92,7 +93,7 @@ MainWindow::MainWindow(QWidget* parent) :
if (pos.rx() < screenSize.width() && pos.ry() < screenSize.height())
move(pos);
} else
resize(1054, 600);
resize(800, 600);
win_sparkle_set_appcast_url("http://dl.ring.cx/windows/winsparkle-ring.xml");
win_sparkle_set_app_details(L"Savoir-faire Linux", L"Ring", QString(NIGHTLY_VERSION).toStdWString().c_str());
......@@ -125,7 +126,6 @@ MainWindow::MainWindow(QWidget* parent) :
MainWindow::~MainWindow()
{
delete ui;
delete navStack_;
}
void
......@@ -197,7 +197,7 @@ MainWindow::createThumbBar()
settings->setIcon(icon);
settings->setDismissOnClick(true);
connect(settings, &QWinThumbnailToolButton::clicked, [this]() {
navStack_->onNavigationRequested(ScreenEnum::ConfScreen);
Utils::slidePage(ui->navStack, ui->configurationwidget);
});
thumbbar->addButton(settings);
......
......@@ -24,7 +24,10 @@
#include <QMouseEvent>
#include <QNetworkConfigurationManager>
#include "navstack.h"
#include "navwidget.h"
// LRC
#include "call.h"
static constexpr char IDM_ABOUTBOX = 0x0010;
......@@ -60,6 +63,5 @@ private:
explicit MainWindow(QWidget* parent = 0);
~MainWindow();
Ui::MainWindow* ui;
NavStack* navStack_;
QNetworkConfigurationManager netManager_;
};
......@@ -462,29 +462,29 @@
<number>0</number>
</property>
<item>
<layout class="QGridLayout" name="gridLayout">
<property name="sizeConstraint">
<enum>QLayout::SetNoConstraint</enum>
</property>
<property name="spacing">
<number>0</number>
</property>
<item row="0" column="0">
<widget class="QStackedWidget" name="stackedWidgetView">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
</layout>
<widget class="QStackedWidget" name="navStack">
<widget class="CallWidget" name="callwidget"/>
<widget class="ConfigurationWidget" name="configurationwidget"/>
</widget>
</item>
</layout>
</widget>
</widget>
<layoutdefault spacing="6" margin="11"/>
<customwidgets>
<customwidget>
<class>CallWidget</class>
<extends>QWidget</extends>
<header>callwidget.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>ConfigurationWidget</class>
<extends>QWidget</extends>
<header>configurationwidget.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources>
<include location="ressources.qrc"/>
</resources>
......
/***************************************************************************
* Copyright (C) 2015-2017 by Savoir-faire Linux *
* Author: Edric Ladent Milaret <edric.ladent-milaret@savoirfairelinux.com>*
* *
* This program is free 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 *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
**************************************************************************/
#include "navstack.h"
#include <QPropertyAnimation>
NavStack::NavStack(QStackedWidget* stack, QWidget *parent)
: stack_(stack)
{
Q_UNUSED(parent)
navList_.append(new CallWidget());
navList_.append(new ConfigurationWidget());
for (int i = 0; i < END; i++) {
stack_->addWidget(navList_[i]);
connect(navList_[i],
SIGNAL(NavigationRequested(ScreenEnum)),
this,
SLOT(onNavigationRequested(ScreenEnum)));
}
slideStacked_ = new QPropertyAnimation();
slideStacked_->setPropertyName("pos");
slideStacked_->setDuration(animDuration_);
slideStacked_->setEasingCurve(QEasingCurve::OutQuad);
}
NavStack::~NavStack()
{
for (int i = 0; i < END; i++) {
delete navList_[i];
}
delete slideStacked_;
}
NavWidget*
NavStack::getNavWidget(ScreenEnum wantedNavWidget)
{
return navList_[wantedNavWidget];
}
void
NavStack::onNavigationRequested(ScreenEnum screen)
{
if (navList_[screen] == stack_->currentWidget())
return;
stack_->setCurrentWidget(navList_[screen]);
stackNav_.append(screen);
slideStacked_->setTargetObject(navList_[screen]);
if(screen == CallScreen) {
slideStacked_->setStartValue(-QPoint(navList_[screen]->width(), navList_[screen]->y()));
((CallWidget*) stack_->currentWidget())->findRingAccount();
}
else
slideStacked_->setStartValue(QPoint(navList_[screen]->width(), navList_[screen]->y()));
slideStacked_->setEndValue(QPoint(navList_[screen]->x(), navList_[screen]->y()));
slideStacked_->start();
}
/***************************************************************************
* Copyright (C) 2015-2017 by Savoir-faire Linux *
* Author: Edric Ladent Milaret <edric.ladent-milaret@savoirfairelinux.com>*
* *
* This program is free 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 *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
**************************************************************************/
#pragma once
#include <QStackedWidget>
#include <QStack>
#include "navwidget.h"
#include "configurationwidget.h"
#include "callwidget.h"
class NavStack : public QWidget
{
Q_OBJECT
public:
NavStack(QStackedWidget* stack, QWidget* parent = nullptr);
~NavStack();
NavWidget* getNavWidget(ScreenEnum wantedNavWidget);
public slots:
void onNavigationRequested(ScreenEnum screen);
private:
QStackedWidget* stack_;
QList<NavWidget*> navList_;
QStack<ScreenEnum> stackNav_;
QPropertyAnimation* slideStacked_;
constexpr static int animDuration_ = 200; //msecs
};
......@@ -32,6 +32,8 @@
#include <QObject>
#include <QErrorMessage>
#include <QPainter>
#include <QStackedWidget>
#include <QPropertyAnimation>
bool
Utils::CreateStartupLink()
......@@ -208,3 +210,19 @@ Utils::getCirclePhoto(const QImage original, int sizePhoto)
painter.drawImage(0, 0, scaledPhoto, margin, 0);
return target;
}
void
Utils::slidePage(QStackedWidget* stack, QWidget* widget, bool toRight)
{
if (stack->indexOf(widget) != -1 && stack->currentWidget() != widget){
QPropertyAnimation* pageAnim = new QPropertyAnimation();
int dir = (toRight ? -1 : 1);
stack->setCurrentWidget(widget);
pageAnim->setTargetObject(widget);
pageAnim->setDuration(animDuration_);
pageAnim->setStartValue(QPoint(widget->width() * dir, widget->y()));
pageAnim->setEndValue(QPoint(widget->x(), widget->y()));
pageAnim->setEasingCurve(QEasingCurve::OutQuad);
pageAnim->start();
}
}
......@@ -30,19 +30,22 @@
#include <string>
#include <QString>
#include <QImage>
#include <QStackedWidget>
class Utils
namespace Utils
{
public:
static bool CreateStartupLink();
static void DeleteStartupLink();
static bool CreateLink(LPCWSTR lpszPathObj, LPCWSTR lpszPathLink);
static bool CheckStartupLink();
static QString GetRingtonePath();
static QString GenGUID();
static QString GetISODate();
static QString GetCurrentUserName();
static void InvokeMailto(const QString& subject, const QString& body, const QString& attachement = QString());
static QImage getCirclePhoto(const QImage original, int sizePhoto);
};
constexpr int animDuration_ = 200; // animation duration for sliding page in ms
bool CreateStartupLink();
void DeleteStartupLink();
bool CreateLink(LPCWSTR lpszPathObj, LPCWSTR lpszPathLink);
bool CheckStartupLink();
QString GetRingtonePath();
QString GenGUID();
QString GetISODate();
QString GetCurrentUserName();
void InvokeMailto(const QString& subject, const QString& body, const QString& attachement = QString());
QImage getCirclePhoto(const QImage original, int sizePhoto);
void slidePage(QStackedWidget *stack, QWidget *widget, bool toRight = false);
}
......@@ -48,7 +48,6 @@ public:
// Overrided function
protected slots:
void accept();
void closeEvent(QCloseEvent* event);
//UI Slots
private slots:
......@@ -66,6 +65,7 @@ private slots:
void timeoutNameLookupTimer();
void on_photoTaken(QString fileName);
void on_signUpCheckbox_toggled(bool checked);
void closeEvent(QCloseEvent* event);
private:
Ui::WizardDialog* ui;
......
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