From 978cc65ac13c72741f47849c42ced58621a907d6 Mon Sep 17 00:00:00 2001 From: Edric Milaret Date: Mon, 8 Feb 2016 11:18:08 -0500 Subject: [PATCH] Revert "ui: fixes for combar and smartlist" This reverts commit 6a419d8c00b41411d3a5d00a5e84279992c1f859. Change-Id: I9a0229428181e576bde1063dc9f1cec294fde815 --- callwidget.cpp | 7 ++-- combar.cpp | 16 ++++----- combar.h | 9 +++-- combar.ui | 22 ++---------- smartlist.cpp | 95 ++++++++++++++++++++++++++++++-------------------- smartlist.h | 13 +++---- 6 files changed, 81 insertions(+), 81 deletions(-) diff --git a/callwidget.cpp b/callwidget.cpp index 516354a..be76d4f 100644 --- a/callwidget.cpp +++ b/callwidget.cpp @@ -58,6 +58,8 @@ CallWidget::CallWidget(QWidget* parent) : menu_(new QMenu()), imDelegate_(new ImDelegate()) { + setMouseTracking(true); + ui->setupUi(this); welcomePageAnim_ = new QPropertyAnimation(ui->welcomePage, "pos", this); @@ -158,8 +160,6 @@ CallWidget::CallWidget(QWidget* parent) : setupOutOfCallIM(); setupSmartListMenu(); - connect(ui->smartList, &SmartList::btnVideoClicked, this, &CallWidget::on_btnvideo_clicked); - } catch (const std::exception& e) { qDebug() << "INIT ERROR" << e.what(); } @@ -473,9 +473,6 @@ CallWidget::on_cancelButton_clicked() void CallWidget::on_smartList_doubleClicked(const QModelIndex& index) { - ui->smartList->reset(); - ui->smartList->setCurrentIndex(index); - auto realIndex = RecentModel::instance().peopleProxy()->mapToSource(index); if (RecentModel::instance().hasActiveCall(realIndex)) return; diff --git a/combar.cpp b/combar.cpp index 23bf47e..d21c145 100644 --- a/combar.cpp +++ b/combar.cpp @@ -16,24 +16,24 @@ * along with this program. If not, see . * **************************************************************************/ -#include "ui_combar.h" - #include "combar.h" - +#include "ui_combar.h" ComBar::ComBar(QWidget* parent) : QWidget(parent), ui(new Ui::ComBar) { ui->setupUi(this); - connect(ui->btnvideo, &QPushButton::clicked , this , [=](){ - emit btnVideoClicked(); - }); - } ComBar::~ComBar() { - disconnect(this); delete ui; } + +void +ComBar::moveToRow(const QRect& rect) +{ + move(rect.right() - width() - 5, + rect.bottom() - height() - (rect.height()/4)); +} diff --git a/combar.h b/combar.h index dd9a706..3465c94 100644 --- a/combar.h +++ b/combar.h @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2015-2016 by Savoir-faire Linux * + * Copyright (C) 2015-2016 by Savoir-faire Linux * * Author: Jäger Nicolas * * * * This program is free software; you can redistribute it and/or modify * @@ -31,10 +31,9 @@ public: explicit ComBar(QWidget* parent = 0); ~ComBar(); +public slots: + void moveToRow(const QRect& rect); + private: Ui::ComBar* ui; - -signals: - void btnVideoClicked() const; - }; diff --git a/combar.ui b/combar.ui index 7e8f2b1..e8f7e49 100644 --- a/combar.ui +++ b/combar.ui @@ -6,8 +6,8 @@ 0 0 - 578 - 112 + 30 + 30 @@ -30,24 +30,11 @@ 0 - 5 + 0 0 - - - - Qt::Horizontal - - - - 40 - 20 - - - - @@ -68,9 +55,6 @@ 30 - - true - diff --git a/smartlist.cpp b/smartlist.cpp index fef1b1c..36230ae 100644 --- a/smartlist.cpp +++ b/smartlist.cpp @@ -17,7 +17,7 @@ **************************************************************************/ #include -#include +#include #include #include @@ -26,29 +26,15 @@ #include "smartlist.h" SmartList::SmartList(QWidget *parent) : - QTreeView(parent) + QTreeView(parent), + comBar_(new ComBar(this)) { - verticalScrollBar()->hide(); - - connect(this, &QAbstractItemView::entered, [this](const QModelIndex & index) { - removeCombar(); - if (auto widget = indexWidget(index)) { - widget->setVisible(true); - } else { - ComBar* bar = new ComBar(); - setIndexWidget(index, bar); - connect(bar, &ComBar::btnVideoClicked, this, [=](){ emit btnVideoClicked(); }); - } - hoveredRow_ = index; - }); - - setVerticalScrollMode(ScrollPerPixel); } SmartList::~SmartList() { - + delete comBar_; } void @@ -56,6 +42,8 @@ SmartList::enterEvent(QEvent* event) { Q_UNUSED(event); verticalScrollBar()->show(); + + repaint(0, 0, width(), height()); } void @@ -63,40 +51,71 @@ SmartList::leaveEvent(QEvent* event) { Q_UNUSED(event); + smartListDelegate_->setRowHighlighted(-1); + + currentRow_ = -1; + + if (smartListDelegate_) + smartListDelegate_->setRowHighlighted(currentRow_); + verticalScrollBar()->hide(); - removeCombar(); + comBar_->hide(); } void -SmartList::setSmartListItemDelegate(SmartListDelegate* delegate) +SmartList::wheelEvent(QWheelEvent* event) { - if (delegate) - { - setItemDelegate(delegate); - smartListDelegate_ = delegate; - } + currentRow_ = -1; + + comBar_->hide(); + + smartListDelegate_->setRowHighlighted(currentRow_); + + repaint(0, 0, width(), height()); + + QTreeView::wheelEvent(event); } -bool -SmartList::eventFilter(QObject* watched, QEvent* event) +void +SmartList::paintEvent(QPaintEvent* event) { + QTreeView::paintEvent(event); - if (qobject_cast(watched) && event->type() == QEvent::Enter) { - removeCombar(); - return true; - } - - return QObject::eventFilter(watched, event); + if (currentRow_ > -1) + comBar_->show(); + else + comBar_->hide(); } void -SmartList::removeCombar() +SmartList::mouseMoveEvent(QMouseEvent* event) { - if(not hoveredRow_.isValid()) - return; + QModelIndex index = indexAt(event->pos()); + + repaint(0, 0, width(), height()); + + currentRow_ = index.row(); - if (auto widget = indexWidget(hoveredRow_)) { - widget->setVisible(false); + if (smartListDelegate_) + { + smartListDelegate_->setRowHighlighted(currentRow_); + + if (currentRow_ > -1) + comBar_->show(); + else + comBar_->hide(); + } + QTreeView::mouseMoveEvent(event); +} + +void +SmartList::setSmartListItemDelegate(SmartListDelegate* delegate) +{ + if (delegate) + { + setItemDelegate(delegate); + smartListDelegate_ = delegate; + connect(smartListDelegate_ , &SmartListDelegate::rowSelected , comBar_, &ComBar::moveToRow); } } diff --git a/smartlist.h b/smartlist.h index 3394d2d..d2f587c 100644 --- a/smartlist.h +++ b/smartlist.h @@ -21,6 +21,7 @@ #include class SmartListDelegate; +class ComBar; class SmartList : public QTreeView { @@ -33,13 +34,13 @@ public: protected: void enterEvent(QEvent* event); void leaveEvent(QEvent* event); - bool eventFilter(QObject* watched, QEvent* event); + void mouseMoveEvent(QMouseEvent* event); + void wheelEvent(QWheelEvent* event); + void paintEvent(QPaintEvent* event); private: - SmartListDelegate* smartListDelegate_; - QPersistentModelIndex hoveredRow_; - void removeCombar(); + int currentRow_ = -1; + SmartListDelegate* smartListDelegate_; + ComBar* comBar_; -signals: - void btnVideoClicked() const; }; -- GitLab