summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt2
-rw-r--r--include/MainWindow.h3
-rw-r--r--include/SlidingStackWidget.h88
-rw-r--r--src/LoginPage.cc2
-rw-r--r--src/MainWindow.cc40
-rw-r--r--src/SlidingStackWidget.cc157
-rw-r--r--src/UserInfoWidget.cc8
7 files changed, 19 insertions, 281 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index db0523d5..699623bd 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -135,7 +135,6 @@ set(SRC_FILES
     src/RoomState.cc
     src/Register.cc
     src/RegisterPage.cc
-    src/SlidingStackWidget.cc
     src/Splitter.cc
     src/Sync.cc
     src/TextInputWidget.cc
@@ -216,7 +215,6 @@ qt5_wrap_cpp(MOC_HEADERS
     include/RoomList.h
     include/Splitter.h
     include/UserInfoWidget.h
-    include/SlidingStackWidget.h
     include/TopRoomBar.h
     include/TrayIcon.h
     include/TextInputWidget.h
diff --git a/include/MainWindow.h b/include/MainWindow.h
index de535d35..85cd5a70 100644
--- a/include/MainWindow.h
+++ b/include/MainWindow.h
@@ -26,7 +26,6 @@
 #include "MatrixClient.h"
 #include "OverlayModal.h"
 #include "RegisterPage.h"
-#include "SlidingStackWidget.h"
 #include "TrayIcon.h"
 #include "WelcomePage.h"
 
@@ -78,7 +77,7 @@ private:
         RegisterPage *register_page_;
 
         // A stacked widget that handles the transitions between widgets.
-        SlidingStackWidget *sliding_stack_;
+        QStackedWidget *pageStack_;
 
         // The main chat area.
         ChatPage *chat_page_;
diff --git a/include/SlidingStackWidget.h b/include/SlidingStackWidget.h
deleted file mode 100644
index c2f329d6..00000000
--- a/include/SlidingStackWidget.h
+++ /dev/null
@@ -1,88 +0,0 @@
-/*
- * nheko Copyright (C) 2017  Konstantinos Sideris <siderisk@auth.gr>
- *
- * 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 <QDebug>
-#include <QEasingCurve>
-#include <QParallelAnimationGroup>
-#include <QPropertyAnimation>
-#include <QStackedWidget>
-#include <QWidget>
-
-/*
- * SlidingStackWidget allows smooth side shifting of widgets,
- * in addition to the hard switching from one to another offered
- * by QStackedWidget.
- */
-
-class SlidingStackWidget : public QStackedWidget
-{
-        Q_OBJECT
-
-public:
-        // Defines the animation direction.
-        enum class AnimationDirection { LEFT_TO_RIGHT, RIGHT_TO_LEFT, AUTOMATIC };
-
-        SlidingStackWidget(QWidget *parent);
-        ~SlidingStackWidget();
-
-public slots:
-        // Move to the next widget.
-        void slideInNext();
-
-        // Move to the previous widget.
-        void slideInPrevious();
-
-        // Move to a widget by index.
-        void slideInIndex(int index, AnimationDirection direction = AnimationDirection::AUTOMATIC);
-
-        int getWidgetIndex(QWidget *widget);
-signals:
-        // Internal signal to alert the engine for the animation's end.
-        void animationFinished();
-
-protected slots:
-        // Internal slot to handle the end of the animation.
-        void onAnimationFinished();
-
-protected:
-        // The method that does the main work for the widget transition.
-        void slideInWidget(QWidget *widget,
-                           AnimationDirection direction = AnimationDirection::AUTOMATIC);
-
-        // Indicates whether or not the animation is active.
-        bool active_;
-
-        // The widget currently displayed.
-        QWidget *window_;
-
-        // The speed of the animation in milliseconds.
-        int speed_;
-
-        // The animation type.
-        QEasingCurve::Type animation_type_;
-
-        // Current widget's index.
-        int now_;
-
-        // Reference point.
-        QPoint current_position_;
-
-        // Next widget's to show index.
-        int next_;
-};
diff --git a/src/LoginPage.cc b/src/LoginPage.cc
index 6a22fa1b..2f4178dd 100644
--- a/src/LoginPage.cc
+++ b/src/LoginPage.cc
@@ -78,7 +78,7 @@ LoginPage::LoginPage(QSharedPointer<MatrixClient> client, QWidget *parent)
         matrixid_input_->setPlaceholderText(tr("e.g @joe:matrix.org"));
 
         spinner_ = new LoadingIndicator(this);
-        spinner_->setColor("#acc7dc");
+        spinner_->setColor("#333333");
         spinner_->setFixedHeight(40);
         spinner_->setFixedWidth(40);
         spinner_->hide();
diff --git a/src/MainWindow.cc b/src/MainWindow.cc
index 531bae8b..39fb1d2a 100644
--- a/src/MainWindow.cc
+++ b/src/MainWindow.cc
@@ -15,8 +15,8 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#include "MainWindow.h"
 #include "Config.h"
+#include "MainWindow.h"
 
 #include <QApplication>
 #include <QLayout>
@@ -55,13 +55,13 @@ MainWindow::MainWindow(QWidget *parent)
         chat_page_     = new ChatPage(client_, this);
 
         // Initialize sliding widget manager.
-        sliding_stack_ = new SlidingStackWidget(this);
-        sliding_stack_->addWidget(welcome_page_);
-        sliding_stack_->addWidget(login_page_);
-        sliding_stack_->addWidget(register_page_);
-        sliding_stack_->addWidget(chat_page_);
+        pageStack_ = new QStackedWidget(this);
+        pageStack_->addWidget(welcome_page_);
+        pageStack_->addWidget(login_page_);
+        pageStack_->addWidget(register_page_);
+        pageStack_->addWidget(chat_page_);
 
-        setCentralWidget(sliding_stack_);
+        setCentralWidget(pageStack_);
 
         connect(welcome_page_, SIGNAL(userLogin()), this, SLOT(showLoginPage()));
         connect(welcome_page_, SIGNAL(userRegister()), this, SLOT(showRegisterPage()));
@@ -157,17 +157,14 @@ MainWindow::showChatPage(QString userid, QString homeserver, QString token)
         settings.setValue("auth/home_server", homeserver);
         settings.setValue("auth/user_id", userid);
 
-        int index                = sliding_stack_->getWidgetIndex(chat_page_);
         int modalOpacityDuration = 300;
 
         // If we go directly from the welcome page don't show an animation.
-        if (sliding_stack_->currentIndex() == 0) {
-                sliding_stack_->setCurrentIndex(index);
+        if (pageStack_->currentIndex() == 0)
                 modalOpacityDuration = 0;
-        } else {
-                sliding_stack_->slideInIndex(index,
-                                             SlidingStackWidget::AnimationDirection::LEFT_TO_RIGHT);
-        }
+
+        QTimer::singleShot(
+          modalOpacityDuration + 100, this, [=]() { pageStack_->setCurrentWidget(chat_page_); });
 
         if (spinner_ == nullptr) {
                 spinner_ = new LoadingIndicator(this);
@@ -192,28 +189,19 @@ MainWindow::showChatPage(QString userid, QString homeserver, QString token)
 void
 MainWindow::showWelcomePage()
 {
-        int index = sliding_stack_->getWidgetIndex(welcome_page_);
-
-        if (sliding_stack_->currentIndex() == sliding_stack_->getWidgetIndex(login_page_))
-                sliding_stack_->slideInIndex(index,
-                                             SlidingStackWidget::AnimationDirection::RIGHT_TO_LEFT);
-        else
-                sliding_stack_->slideInIndex(index,
-                                             SlidingStackWidget::AnimationDirection::LEFT_TO_RIGHT);
+        pageStack_->setCurrentWidget(welcome_page_);
 }
 
 void
 MainWindow::showLoginPage()
 {
-        int index = sliding_stack_->getWidgetIndex(login_page_);
-        sliding_stack_->slideInIndex(index, SlidingStackWidget::AnimationDirection::LEFT_TO_RIGHT);
+        pageStack_->setCurrentWidget(login_page_);
 }
 
 void
 MainWindow::showRegisterPage()
 {
-        int index = sliding_stack_->getWidgetIndex(register_page_);
-        sliding_stack_->slideInIndex(index, SlidingStackWidget::AnimationDirection::RIGHT_TO_LEFT);
+        pageStack_->setCurrentWidget(register_page_);
 }
 
 void
diff --git a/src/SlidingStackWidget.cc b/src/SlidingStackWidget.cc
deleted file mode 100644
index fd76e993..00000000
--- a/src/SlidingStackWidget.cc
+++ /dev/null
@@ -1,157 +0,0 @@
-/*
- * nheko Copyright (C) 2017  Konstantinos Sideris <siderisk@auth.gr>
- *
- * 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 "SlidingStackWidget.h"
-
-SlidingStackWidget::SlidingStackWidget(QWidget *parent)
-  : QStackedWidget(parent)
-{
-        window_ = parent;
-
-        if (parent == Q_NULLPTR) {
-                qDebug() << "Using nullptr for parent";
-                window_ = this;
-        }
-
-        current_position_ = QPoint(0, 0);
-        speed_            = 400;
-        now_              = 0;
-        next_             = 0;
-        active_           = false;
-        animation_type_   = QEasingCurve::InOutCirc;
-}
-
-SlidingStackWidget::~SlidingStackWidget()
-{
-}
-
-void
-SlidingStackWidget::slideInNext()
-{
-        int now = currentIndex();
-
-        if (now < count() - 1)
-                slideInIndex(now + 1);
-}
-
-void
-SlidingStackWidget::slideInPrevious()
-{
-        int now = currentIndex();
-
-        if (now > 0)
-                slideInIndex(now - 1);
-}
-
-void
-SlidingStackWidget::slideInIndex(int index, AnimationDirection direction)
-{
-        // Take into consideration possible index overflow/undeflow.
-        if (index > count() - 1) {
-                direction = AnimationDirection::RIGHT_TO_LEFT;
-                index     = index % count();
-        } else if (index < 0) {
-                direction = AnimationDirection::LEFT_TO_RIGHT;
-                index     = (index + count()) % count();
-        }
-
-        slideInWidget(widget(index), direction);
-}
-
-void
-SlidingStackWidget::slideInWidget(QWidget *next_widget, AnimationDirection direction)
-{
-        // If an animation is currenlty executing we should wait for it to finish before
-        // another transition can start.
-        if (active_)
-                return;
-
-        active_ = true;
-
-        int now  = currentIndex();
-        int next = indexOf(next_widget);
-
-        if (now == next) {
-                active_ = false;
-                return;
-        }
-
-        int offset_x = frameRect().width();
-
-        next_widget->setGeometry(0, 0, offset_x, 0);
-
-        if (direction == AnimationDirection::LEFT_TO_RIGHT) {
-                offset_x = -offset_x;
-        }
-
-        QPoint pnext      = next_widget->pos();
-        QPoint pnow       = widget(now)->pos();
-        current_position_ = pnow;
-
-        // Reposition the next widget outside of the display area.
-        next_widget->move(pnext.x() - offset_x, pnext.y());
-
-        // Make the widget visible.
-        next_widget->show();
-        next_widget->raise();
-
-        // Animate both the next and now widget.
-        QPropertyAnimation *animation_now = new QPropertyAnimation(widget(now), "pos", this);
-
-        animation_now->setDuration(speed_);
-        animation_now->setEasingCurve(animation_type_);
-        animation_now->setStartValue(QPoint(pnow.x(), pnow.y()));
-        animation_now->setEndValue(QPoint(pnow.x() + offset_x, pnow.y()));
-
-        QPropertyAnimation *animation_next = new QPropertyAnimation(next_widget, "pos", this);
-
-        animation_next->setDuration(speed_);
-        animation_next->setEasingCurve(animation_type_);
-        animation_next->setStartValue(QPoint(pnext.x() - offset_x, pnext.y()));
-        animation_next->setEndValue(QPoint(pnext.x(), pnext.y()));
-
-        QParallelAnimationGroup *animation_group = new QParallelAnimationGroup(this);
-
-        animation_group->addAnimation(animation_now);
-        animation_group->addAnimation(animation_next);
-
-        connect(animation_group, SIGNAL(finished()), this, SLOT(onAnimationFinished()));
-
-        next_ = next;
-        now_  = now;
-        animation_group->start();
-}
-
-void
-SlidingStackWidget::onAnimationFinished()
-{
-        setCurrentIndex(next_);
-
-        // The old widget is no longer necessary so we can hide it and
-        // move it back to its original position.
-        widget(now_)->hide();
-        widget(now_)->move(current_position_);
-
-        active_ = false;
-        emit animationFinished();
-}
-
-int
-SlidingStackWidget::getWidgetIndex(QWidget *widget)
-{
-        return indexOf(widget);
-}
diff --git a/src/UserInfoWidget.cc b/src/UserInfoWidget.cc
index b5926c58..463b3c6c 100644
--- a/src/UserInfoWidget.cc
+++ b/src/UserInfoWidget.cc
@@ -103,7 +103,7 @@ UserInfoWidget::UserInfoWidget(QWidget *parent)
 
                 if (logoutModal_ == nullptr) {
                         logoutModal_ = new OverlayModal(MainWindow::instance(), logoutDialog_);
-                        logoutModal_->setDuration(100);
+                        logoutModal_->setDuration(0);
                         logoutModal_->setColor(QColor(55, 55, 55, 170));
                 }
 
@@ -116,10 +116,8 @@ UserInfoWidget::closeLogoutDialog(bool isLoggingOut)
 {
         logoutModal_->fadeOut();
 
-        if (isLoggingOut) {
-                // Waiting for the modal to fade out.
-                QTimer::singleShot(100, this, [=]() { emit logout(); });
-        }
+        if (isLoggingOut)
+                emit logout();
 }
 
 UserInfoWidget::~UserInfoWidget()