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 <QMessageBox>
#include <QSettings> #include <QSettings>
#include <QFileInfo> #include <QFileInfo>
#include <QPalette>
#include <QColor>
#include <QBrush>
#include <QTimer>
#include <QFile> #include <QFile>
#include <QMenu> #include <QMenu>
#include <QUrl> #include <QUrl>
@ -40,6 +44,13 @@ SavegameWidget::SavegameWidget(QWidget *parent) :
ui->cmdView->setVisible(false); ui->cmdView->setVisible(false);
ui->cmdDelete->setVisible(false); ui->cmdDelete->setVisible(false);
ui->cbSelected->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 = ""; sgdPath = "";
sgdStr = ""; sgdStr = "";
sgdata = 0; sgdata = 0;
@ -95,15 +106,6 @@ void SavegameWidget::on_cmdView_clicked()
delete savegameDialog; delete savegameDialog;
} }
void SavegameWidget::mouseDoubleClickEvent(QMouseEvent *ev)
{
QWidget::mouseDoubleClickEvent(ev);
if (ev->button() == Qt::LeftButton)
{
on_cmdView_clicked();
}
}
void SavegameWidget::setChecked(bool isChecked) void SavegameWidget::setChecked(bool isChecked)
{ {
@ -115,6 +117,44 @@ void SavegameWidget::on_savegameSelected()
setChecked(true); 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) void SavegameWidget::contextMenuEvent(QContextMenuEvent *ev)
{ {
QMenu contextMenu(this); QMenu contextMenu(this);

View File

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

View File

@ -14,6 +14,30 @@
<string>Savegame Widget</string> <string>Savegame Widget</string>
</property> </property>
<layout class="QHBoxLayout" name="hlSavegameContent"> <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> <item>
<widget class="QCheckBox" name="cbSelected"> <widget class="QCheckBox" name="cbSelected">
<property name="text"> <property name="text">
@ -76,6 +100,9 @@
</item> </item>
</layout> </layout>
</widget> </widget>
</item>
</layout>
</widget>
<resources> <resources>
<include location="res/app.qrc"/> <include location="res/app.qrc"/>
</resources> </resources>

View File

@ -25,6 +25,7 @@
#include "PictureCopy.h" #include "PictureCopy.h"
#include <QMessageBox> #include <QMessageBox>
#include <QPixmap> #include <QPixmap>
#include <QTimer>
#include <QDebug> #include <QDebug>
#include <QMenu> #include <QMenu>
#include <QFile> #include <QFile>
@ -39,6 +40,13 @@ SnapmaticWidget::SnapmaticWidget(ProfileDatabase *profileDB, DatabaseThread *thr
ui->cmdExport->setVisible(false); ui->cmdExport->setVisible(false);
ui->cmdDelete->setVisible(false); ui->cmdDelete->setVisible(false);
ui->cbSelected->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 = ""; picPath = "";
picStr = ""; picStr = "";
smpic = 0; 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) void SnapmaticWidget::mouseDoubleClickEvent(QMouseEvent *ev)
{ {
QWidget::mouseDoubleClickEvent(ev); QWidget::mouseDoubleClickEvent(ev);
if (ev->button() == Qt::LeftButton) if (ev->button() == Qt::LeftButton)
{ {
clkIssued = true;
on_cmdView_clicked(); on_cmdView_clicked();
} }
} }
void SnapmaticWidget::changeCheckedState()
{
if (!clkIssued)
{
ui->cbSelected->setChecked(!ui->cbSelected->isChecked());
}
}
void SnapmaticWidget::setChecked(bool isChecked) void SnapmaticWidget::setChecked(bool isChecked)
{ {
ui->cbSelected->setChecked(isChecked); ui->cbSelected->setChecked(isChecked);

View File

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

View File

@ -13,7 +13,31 @@
<property name="windowTitle"> <property name="windowTitle">
<string>Snapmatic Widget</string> <string>Snapmatic Widget</string>
</property> </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> <item>
<widget class="QCheckBox" name="cbSelected"> <widget class="QCheckBox" name="cbSelected">
<property name="text"> <property name="text">
@ -98,6 +122,9 @@
</item> </item>
</layout> </layout>
</widget> </widget>
</item>
</layout>
</widget>
<resources/> <resources/>
<connections/> <connections/>
</ui> </ui>