From 30fce321613b234934512dd06a7ef8f4b0929d7b Mon Sep 17 00:00:00 2001 From: Konstantinos Sideris Date: Fri, 19 May 2017 17:23:36 +0300 Subject: [PATCH] Remove RoomList UI form --- CMakeLists.txt | 5 +- forms/RoomList.ui | 157 --------------------------------------------- include/RoomList.h | 14 ++-- src/RoomList.cc | 41 ++++++++---- 4 files changed, 37 insertions(+), 180 deletions(-) delete mode 100644 forms/RoomList.ui diff --git a/CMakeLists.txt b/CMakeLists.txt index e2337fed..e45c3560 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -149,10 +149,7 @@ include_directories(include/ui) include_directories(include/events) include_directories(include/events/messages) -qt5_wrap_ui (UI_HEADERS - forms/ChatPage.ui - forms/RoomList.ui -) +qt5_wrap_ui (UI_HEADERS forms/ChatPage.ui) qt5_wrap_cpp(MOC_HEADERS include/ChatPage.h diff --git a/forms/RoomList.ui b/forms/RoomList.ui deleted file mode 100644 index b56a75ab..00000000 --- a/forms/RoomList.ui +++ /dev/null @@ -1,157 +0,0 @@ - - - RoomList - - - - 0 - 0 - 423 - 500 - - - - - 0 - 0 - - - - - 0 - 500 - - - - Form - - - QWidget { -background-color: #f8fbfe; -color: #ebebeb; -} - -QScrollBar:vertical { - background-color: #f8fbfe; - width: 8px; - border-radius: 20px; - margin: 0px 2px 0 2px; -} - -QScrollBar::handle:vertical { - border-radius: 50px; - background-color: #d6dde3; -} - -QScrollBar::add-line:vertical { - border: none; - background: none; -} - -QScrollBar::sub-line:vertical { - border: none; - background: none; -} - - - - 0 - - - 0 - - - 0 - - - 0 - - - 0 - - - - - 0 - - - - - - 0 - 0 - - - - - 0 - 0 - - - - - 16777215 - 16777215 - - - - Qt::ScrollBarAlwaysOff - - - QAbstractScrollArea::AdjustToContents - - - true - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter - - - - - 0 - 0 - 419 - 496 - - - - - 0 - 0 - - - - - 0 - - - 0 - - - 0 - - - 0 - - - 0 - - - - - 0 - - - - - - - - - - - - - - diff --git a/include/RoomList.h b/include/RoomList.h index 34067430..489083d1 100644 --- a/include/RoomList.h +++ b/include/RoomList.h @@ -17,9 +17,9 @@ #pragma once -#include +#include #include -#include +#include #include #include "MatrixClient.h" @@ -27,11 +27,6 @@ #include "RoomState.h" #include "Sync.h" -namespace Ui -{ -class RoomList; -} - class RoomList : public QWidget { Q_OBJECT @@ -57,7 +52,10 @@ public slots: private: void calculateUnreadMessageCount(); - Ui::RoomList *ui; + QVBoxLayout *topLayout_; + QVBoxLayout *contentsLayout_; + QScrollArea *scrollArea_; + QWidget *scrollAreaContents_; QMap> rooms_; diff --git a/src/RoomList.cc b/src/RoomList.cc index 58053bbd..c3fe16a2 100644 --- a/src/RoomList.cc +++ b/src/RoomList.cc @@ -15,11 +15,8 @@ * along with this program. If not, see . */ -#include "ui_RoomList.h" - #include #include -#include #include #include "RoomInfoListItem.h" @@ -28,16 +25,39 @@ RoomList::RoomList(QSharedPointer client, QWidget *parent) : QWidget(parent) - , ui(new Ui::RoomList) , client_(client) { - ui->setupUi(this); - ui->scrollVerticalLayout->addStretch(1); - setStyleSheet( "QWidget { border: none; }" "QScrollBar:vertical { width: 4px; margin: 2px 0; }"); + QSizePolicy sizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding); + sizePolicy.setHorizontalStretch(0); + sizePolicy.setVerticalStretch(0); + setSizePolicy(sizePolicy); + + setMinimumSize(QSize(0, 500)); + + topLayout_ = new QVBoxLayout(this); + topLayout_->setSpacing(0); + topLayout_->setMargin(0); + + scrollArea_ = new QScrollArea(this); + scrollArea_->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + scrollArea_->setSizeAdjustPolicy(QAbstractScrollArea::AdjustToContents); + scrollArea_->setWidgetResizable(true); + scrollArea_->setAlignment(Qt::AlignLeading | Qt::AlignLeft | Qt::AlignVCenter); + + scrollAreaContents_ = new QWidget(); + + contentsLayout_ = new QVBoxLayout(scrollAreaContents_); + contentsLayout_->setSpacing(0); + contentsLayout_->setMargin(0); + contentsLayout_->addStretch(1); + + scrollArea_->setWidget(scrollAreaContents_); + topLayout_->addWidget(scrollArea_); + connect(client_.data(), SIGNAL(roomAvatarRetrieved(const QString &, const QPixmap &)), this, @@ -46,7 +66,6 @@ RoomList::RoomList(QSharedPointer client, QWidget *parent) RoomList::~RoomList() { - delete ui; } void RoomList::clear() @@ -87,13 +106,13 @@ void RoomList::setInitialRooms(const QMap &states) if (!state.avatar.content().url().toString().isEmpty()) client_->fetchRoomAvatar(room_id, state.avatar.content().url()); - RoomInfoListItem *room_item = new RoomInfoListItem(state, room_id, ui->scrollArea); + RoomInfoListItem *room_item = new RoomInfoListItem(state, room_id, scrollArea_); connect(room_item, &RoomInfoListItem::clicked, this, &RoomList::highlightSelectedRoom); rooms_.insert(room_id, QSharedPointer(room_item)); - int pos = ui->scrollVerticalLayout->count() - 1; - ui->scrollVerticalLayout->insertWidget(pos, room_item); + int pos = contentsLayout_->count() - 1; + contentsLayout_->insertWidget(pos, room_item); } if (rooms_.isEmpty())