Commit 6a419d8c authored by Nicolas Jager's avatar Nicolas Jager

ui: fixes for combar and smartlist

- the background under item hovered is now correct.

- using wheel mouse over the smartlist is fixed.

- the combar has the good behaviour when using the scrollbar of the smartlist

Change-Id: I5086f585aba4bb127783e19ff4307cff5eff7918
Tuleap: #286
Tuleap: #288
Tuleap: #289
parent 389a2296
......@@ -58,8 +58,6 @@ CallWidget::CallWidget(QWidget* parent) :
menu_(new QMenu()),
imDelegate_(new ImDelegate())
{
setMouseTracking(true);
ui->setupUi(this);
welcomePageAnim_ = new QPropertyAnimation(ui->welcomePage, "pos", this);
......@@ -160,6 +158,8 @@ 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,6 +473,9 @@ 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;
......
......@@ -16,24 +16,24 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
**************************************************************************/
#include "combar.h"
#include "ui_combar.h"
#include "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));
}
/***************************************************************************
* Copyright (C) 2015-2016 by Savoir-faire Linux *
* Copyright (C) 2015-2016 by Savoir-faire Linux *
* Author: Jäger Nicolas <nicolas.jager@savoirfairelinux.com> *
* *
* This program is free software; you can redistribute it and/or modify *
......@@ -31,9 +31,10 @@ public:
explicit ComBar(QWidget* parent = 0);
~ComBar();
public slots:
void moveToRow(const QRect& rect);
private:
Ui::ComBar* ui;
signals:
void btnVideoClicked() const;
};
......@@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>30</width>
<height>30</height>
<width>578</width>
<height>112</height>
</rect>
</property>
<property name="sizePolicy">
......@@ -30,11 +30,24 @@
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
<number>5</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="btnvideo">
<property name="sizePolicy">
......@@ -55,6 +68,9 @@
<height>30</height>
</size>
</property>
<property name="mouseTracking">
<bool>true</bool>
</property>
<property name="text">
<string/>
</property>
......
......@@ -17,7 +17,7 @@
**************************************************************************/
#include <QStyledItemDelegate>
#include <qevent.h>
#include <QEvent>
#include <QTreeWidgetItem>
#include <QScrollBar>
......@@ -26,15 +26,29 @@
#include "smartlist.h"
SmartList::SmartList(QWidget *parent) :
QTreeView(parent),
comBar_(new ComBar(this))
QTreeView(parent)
{
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
......@@ -42,8 +56,6 @@ SmartList::enterEvent(QEvent* event)
{
Q_UNUSED(event);
verticalScrollBar()->show();
repaint(0, 0, width(), height());
}
void
......@@ -51,71 +63,40 @@ SmartList::leaveEvent(QEvent* event)
{
Q_UNUSED(event);
smartListDelegate_->setRowHighlighted(-1);
currentRow_ = -1;
if (smartListDelegate_)
smartListDelegate_->setRowHighlighted(currentRow_);
verticalScrollBar()->hide();
comBar_->hide();
removeCombar();
}
void
SmartList::wheelEvent(QWheelEvent* event)
{
currentRow_ = -1;
comBar_->hide();
smartListDelegate_->setRowHighlighted(currentRow_);
repaint(0, 0, width(), height());
QTreeView::wheelEvent(event);
}
void
SmartList::paintEvent(QPaintEvent* event)
SmartList::setSmartListItemDelegate(SmartListDelegate* delegate)
{
QTreeView::paintEvent(event);
if (currentRow_ > -1)
comBar_->show();
else
comBar_->hide();
if (delegate)
{
setItemDelegate(delegate);
smartListDelegate_ = delegate;
}
}
void
SmartList::mouseMoveEvent(QMouseEvent* event)
bool
SmartList::eventFilter(QObject* watched, QEvent* event)
{
QModelIndex index = indexAt(event->pos());
repaint(0, 0, width(), height());
currentRow_ = index.row();
if (smartListDelegate_)
{
smartListDelegate_->setRowHighlighted(currentRow_);
if (currentRow_ > -1)
comBar_->show();
else
comBar_->hide();
if (qobject_cast<QScrollBar*>(watched) && event->type() == QEvent::Enter) {
removeCombar();
return true;
}
QTreeView::mouseMoveEvent(event);
return QObject::eventFilter(watched, event);
}
void
SmartList::setSmartListItemDelegate(SmartListDelegate* delegate)
SmartList::removeCombar()
{
if (delegate)
{
setItemDelegate(delegate);
smartListDelegate_ = delegate;
connect(smartListDelegate_ , &SmartListDelegate::rowSelected , comBar_, &ComBar::moveToRow);
if(not hoveredRow_.isValid())
return;
if (auto widget = indexWidget(hoveredRow_)) {
widget->setVisible(false);
}
}
......@@ -21,7 +21,6 @@
#include <QTreeView>
class SmartListDelegate;
class ComBar;
class SmartList : public QTreeView
{
......@@ -34,13 +33,13 @@ public:
protected:
void enterEvent(QEvent* event);
void leaveEvent(QEvent* event);
void mouseMoveEvent(QMouseEvent* event);
void wheelEvent(QWheelEvent* event);
void paintEvent(QPaintEvent* event);
bool eventFilter(QObject* watched, QEvent* event);
private:
int currentRow_ = -1;
SmartListDelegate* smartListDelegate_;
ComBar* comBar_;
SmartListDelegate* smartListDelegate_;
QPersistentModelIndex hoveredRow_;
void removeCombar();
signals:
void btnVideoClicked() const;
};
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