highlight hovered widgets at the ProfileInterface

This commit is contained in:
Rafael 2016-04-03 05:25:54 +02:00
parent 50809e7a7c
commit 466f739b3a
6 changed files with 275 additions and 138 deletions

View file

@ -27,6 +27,10 @@
#include <QMessageBox>
#include <QSettings>
#include <QFileInfo>
#include <QPalette>
#include <QColor>
#include <QBrush>
#include <QTimer>
#include <QFile>
#include <QMenu>
#include <QUrl>
@ -40,6 +44,13 @@ SavegameWidget::SavegameWidget(QWidget *parent) :
ui->cmdView->setVisible(false);
ui->cmdDelete->setVisible(false);
ui->cbSelected->setVisible(false);
QPalette palette;
QColor highlightBackColor = palette.highlight().color();
QColor highlightTextColor = palette.highlightedText().color();
setStyleSheet(QString("QFrame:hover#SavegameFrame{background-color: rgb(%1, %2, %3); color: rgb(%4, %5, %6)}").arg(QString::number(highlightBackColor.red()), QString::number(highlightBackColor.green()), QString::number(highlightBackColor.blue()), QString::number(highlightTextColor.red()), QString::number(highlightTextColor.green()), QString::number(highlightTextColor.blue())));
clkIssued = 0;
sgdPath = "";
sgdStr = "";
sgdata = 0;
@ -95,15 +106,6 @@ void SavegameWidget::on_cmdView_clicked()
delete savegameDialog;
}
void SavegameWidget::mouseDoubleClickEvent(QMouseEvent *ev)
{
QWidget::mouseDoubleClickEvent(ev);
if (ev->button() == Qt::LeftButton)
{
on_cmdView_clicked();
}
}
void SavegameWidget::setChecked(bool isChecked)
{
@ -115,6 +117,44 @@ void SavegameWidget::on_savegameSelected()
setChecked(true);
}
void SavegameWidget::mousePressEvent(QMouseEvent *ev)
{
ProfileWidget::mouseReleaseEvent(ev);
clkIssued = true;
}
void SavegameWidget::mouseReleaseEvent(QMouseEvent *ev)
{
ProfileWidget::mouseReleaseEvent(ev);
if (ui->cbSelected->isVisible())
{
if (rect().contains(ev->pos()) && ev->button() == Qt::LeftButton)
{
clkIssued = false;
QTimer::singleShot(QApplication::doubleClickInterval(), this, SLOT(changeCheckedState()));
}
}
}
void SavegameWidget::mouseDoubleClickEvent(QMouseEvent *ev)
{
QWidget::mouseDoubleClickEvent(ev);
if (ev->button() == Qt::LeftButton)
{
clkIssued = true;
on_cmdView_clicked();
}
}
void SavegameWidget::changeCheckedState()
{
if (!clkIssued)
{
ui->cbSelected->setChecked(!ui->cbSelected->isChecked());
}
}
void SavegameWidget::contextMenuEvent(QContextMenuEvent *ev)
{
QMenu contextMenu(this);

View file

@ -48,9 +48,12 @@ private slots:
void on_cmdDelete_clicked();
void on_savegameSelected();
void on_cbSelected_stateChanged(int arg1);
void changeCheckedState();
protected:
void mouseDoubleClickEvent(QMouseEvent *ev);
void mouseReleaseEvent(QMouseEvent *ev);
void mousePressEvent(QMouseEvent *ev);
void contextMenuEvent(QContextMenuEvent *ev);
private:
@ -58,6 +61,7 @@ private:
SavegameData *sgdata;
QString sgdPath;
QString sgdStr;
bool clkIssued;
signals:
void savegameDeleted();

View file

@ -14,6 +14,30 @@
<string>Savegame Widget</string>
</property>
<layout class="QHBoxLayout" name="hlSavegameContent">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QFrame" name="SavegameFrame">
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Plain</enum>
</property>
<property name="lineWidth">
<number>0</number>
</property>
<layout class="QHBoxLayout" name="hlSavegame">
<item>
<widget class="QCheckBox" name="cbSelected">
<property name="text">
@ -76,6 +100,9 @@
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<resources>
<include location="res/app.qrc"/>
</resources>

View file

@ -25,6 +25,7 @@
#include "PictureCopy.h"
#include <QMessageBox>
#include <QPixmap>
#include <QTimer>
#include <QDebug>
#include <QMenu>
#include <QFile>
@ -39,6 +40,13 @@ SnapmaticWidget::SnapmaticWidget(ProfileDatabase *profileDB, DatabaseThread *thr
ui->cmdExport->setVisible(false);
ui->cmdDelete->setVisible(false);
ui->cbSelected->setVisible(false);
QPalette palette;
QColor highlightBackColor = palette.highlight().color();
QColor highlightTextColor = palette.highlightedText().color();
setStyleSheet(QString("QFrame:hover#SnapmaticFrame{background-color: rgb(%1, %2, %3); color: rgb(%4, %5, %6)}").arg(QString::number(highlightBackColor.red()), QString::number(highlightBackColor.green()), QString::number(highlightBackColor.blue()), QString::number(highlightTextColor.red()), QString::number(highlightTextColor.green()), QString::number(highlightTextColor.blue())));
clkIssued = 0;
picPath = "";
picStr = "";
smpic = 0;
@ -108,16 +116,43 @@ void SnapmaticWidget::on_cmdDelete_clicked()
}
}
void SnapmaticWidget::mousePressEvent(QMouseEvent *ev)
{
ProfileWidget::mousePressEvent(ev);
}
void SnapmaticWidget::mouseReleaseEvent(QMouseEvent *ev)
{
ProfileWidget::mouseReleaseEvent(ev);
if (ui->cbSelected->isVisible())
{
if (rect().contains(ev->pos()) && ev->button() == Qt::LeftButton)
{
clkIssued = false;
QTimer::singleShot(QApplication::doubleClickInterval(), this, SLOT(changeCheckedState()));
}
}
}
void SnapmaticWidget::mouseDoubleClickEvent(QMouseEvent *ev)
{
QWidget::mouseDoubleClickEvent(ev);
if (ev->button() == Qt::LeftButton)
{
clkIssued = true;
on_cmdView_clicked();
}
}
void SnapmaticWidget::changeCheckedState()
{
if (!clkIssued)
{
ui->cbSelected->setChecked(!ui->cbSelected->isChecked());
}
}
void SnapmaticWidget::setChecked(bool isChecked)
{
ui->cbSelected->setChecked(isChecked);

View file

@ -51,9 +51,12 @@ private slots:
void on_cmdDelete_clicked();
void on_pictureSelected();
void on_cbSelected_stateChanged(int arg1);
void changeCheckedState();
protected:
void mouseDoubleClickEvent(QMouseEvent *ev);
void mouseReleaseEvent(QMouseEvent *ev);
void mousePressEvent(QMouseEvent *ev);
void contextMenuEvent(QContextMenuEvent *ev);
private:
@ -64,6 +67,7 @@ private:
QAction *actSelectPic;
QString picPath;
QString picStr;
bool clkIssued;
signals:
void pictureDeleted();

View file

@ -13,7 +13,31 @@
<property name="windowTitle">
<string>Snapmatic Widget</string>
</property>
<layout class="QHBoxLayout" name="hlSnapmaticWidget">
<layout class="QHBoxLayout" name="hlSnapmaticContent">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QFrame" name="SnapmaticFrame">
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Plain</enum>
</property>
<property name="lineWidth">
<number>0</number>
</property>
<layout class="QHBoxLayout" name="hlSnapmatic">
<item>
<widget class="QCheckBox" name="cbSelected">
<property name="text">
@ -98,6 +122,9 @@
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>