Simplify MainPage and add Connect to core button in clients
authorHannah von Reth <vonreth@kde.org>
Tue, 3 Nov 2015 14:07:13 +0000 (15:07 +0100)
committerHannah von Reth <vonreth@kde.org>
Tue, 3 Nov 2015 14:19:59 +0000 (15:19 +0100)
Instead of overriding the paint function simply use a layout
and a QLabel in MainPage, this also enables us to add a button
to open the connect to core dialog.

This commit also hides the Nick list in a disconnected state,
to make sure the Quassel logo is centred and to keep it in line
with the All Chats view.

src/qtui/mainpage.cpp
src/qtui/mainpage.h
src/qtui/mainwin.cpp
src/qtui/nicklistwidget.cpp
src/qtui/nicklistwidget.h

index 82387ab..a0e5f11 100644 (file)
  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
  ***************************************************************************/
 
+#include <QPushButton>
 #include <QImage>
+#include <QLabel>
+#include <QLayout>
 #include <QPainter>
 
 #include "mainpage.h"
+#include "coreconnectdlg.h"
+#include "client.h"
 
 MainPage::MainPage(QWidget *parent) : QWidget(parent)
 {
-}
-
-
-void MainPage::paintEvent(QPaintEvent *event)
-{
-    Q_UNUSED(event);
-
-    QPainter painter(this);
-    QImage img(":/pics/quassel-logo.png"); // FIXME load externally
-
-    if (img.height() > height() || img.width() > width())
-        img = img.scaled(width(), height(), Qt::KeepAspectRatio, Qt::SmoothTransformation);
-
-    int xmargin = (width() - img.width()) / 2;
-    int ymargin = (height() - img.height()) / 2;
-
-    painter.drawImage(xmargin, ymargin, img);
+    QVBoxLayout *layout = new QVBoxLayout(this);
+    layout->setAlignment(Qt::AlignCenter);
+    QLabel *label = new QLabel(this);
+    label->setPixmap(QPixmap(":/pics/quassel-logo.png"));
+    layout->addWidget(label);
+
+    if (Quassel::runMode() != Quassel::Monolithic) {
+        QPushButton *connectButton = new QPushButton(QIcon::fromTheme("network-connect"), tr("Connect to Core..."));
+        connect(connectButton, &QPushButton::clicked, [this](){
+            CoreConnectDlg dlg(this);
+            if (dlg.exec() == QDialog::Accepted) {
+                AccountId accId = dlg.selectedAccount();
+                if (accId.isValid())
+                    Client::coreConnection()->connectToCore(accId);
+            }
+        });
+        layout->addWidget(connectButton);
+    }
 }
index 0557f8e..0c48b9f 100644 (file)
@@ -30,8 +30,6 @@ class MainPage : public QWidget
 public:
     MainPage(QWidget *parent = 0);
 
-protected:
-    void paintEvent(QPaintEvent *event);
 };
 
 
index bd8727a..95d2e6f 100644 (file)
@@ -879,6 +879,8 @@ void MainWin::setupNickWidget()
     // attach the NickListWidget to the BufferModel and the default selection
     _nickListWidget->setModel(Client::bufferModel());
     _nickListWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
+
+    _nickListWidget->setVisible(false);
 }
 
 
@@ -1131,7 +1133,7 @@ void MainWin::loadLayout()
         _layoutLoaded = true;
         return;
     }
-
+    _nickListWidget->setVisible(true);
     restoreState(state, accountId);
     int bufferViewId = s.value(QString("ActiveBufferView-%1").arg(accountId), -1).toInt();
     if (bufferViewId >= 0)
@@ -1201,6 +1203,7 @@ void MainWin::setDisconnectedState()
         _msgProcessorStatusWidget->setProgress(0, 0);
     updateIcon();
     systemTray()->setState(SystemTray::Passive);
+    _nickListWidget->setVisible(false);
 }
 
 
index d5af971..a47cc6e 100644 (file)
@@ -84,6 +84,19 @@ void NickListWidget::showWidget(bool visible)
     }
 }
 
+void NickListWidget::setVisible(bool visible)
+{
+    QWidget::setVisible(visible);
+    QDockWidget *dock_ = dock();
+    if (!dock_)
+        return;
+
+    if (visible)
+        dock_->show();
+    else
+        dock_->close();
+}
+
 
 void NickListWidget::currentChanged(const QModelIndex &current, const QModelIndex &previous)
 {
index 1b7253f..84fc432 100644 (file)
@@ -43,6 +43,7 @@ public:
 
 public slots:
     void showWidget(bool visible);
+    void setVisible(bool visible) override;
 
 signals:
     void nickSelectionChanged(const QModelIndexList &);