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,64 +14,91 @@
<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="QCheckBox" name="cbSelected">
<property name="text">
<string/>
<widget class="QFrame" name="SavegameFrame">
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="labSavegamePic">
<property name="text">
<string/>
<property name="frameShadow">
<enum>QFrame::Plain</enum>
</property>
<property name="pixmap">
<pixmap resource="res/app.qrc">:/img/savegame.png</pixmap>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="labSavegameStr">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>The Third Way (100%) - 00/00/00 00:00:00</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="cmdView">
<property name="text">
<string>View</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="cmdCopy">
<property name="text">
<string>Copy</string>
</property>
<property name="autoDefault">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="cmdDelete">
<property name="text">
<string>Delete</string>
</property>
<property name="autoDefault">
<bool>true</bool>
<property name="lineWidth">
<number>0</number>
</property>
<layout class="QHBoxLayout" name="hlSavegame">
<item>
<widget class="QCheckBox" name="cbSelected">
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="labSavegamePic">
<property name="text">
<string/>
</property>
<property name="pixmap">
<pixmap resource="res/app.qrc">:/img/savegame.png</pixmap>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="labSavegameStr">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>The Third Way (100%) - 00/00/00 00:00:00</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="cmdView">
<property name="text">
<string>View</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="cmdCopy">
<property name="text">
<string>Copy</string>
</property>
<property name="autoDefault">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="cmdDelete">
<property name="text">
<string>Delete</string>
</property>
<property name="autoDefault">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>

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,87 +13,114 @@
<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="QCheckBox" name="cbSelected">
<property name="text">
<string/>
<widget class="QFrame" name="SnapmaticFrame">
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="labPicture">
<property name="minimumSize">
<size>
<width>48</width>
<height>27</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>48</width>
<height>27</height>
</size>
<property name="frameShadow">
<enum>QFrame::Plain</enum>
</property>
<property name="lineWidth">
<number>0</number>
</property>
<property name="text">
<string/>
</property>
<property name="scaledContents">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="labPicStr">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>PHOTO - 00/00/00 00:00:00</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="cmdView">
<property name="text">
<string>View</string>
</property>
<property name="autoDefault">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="cmdCopy">
<property name="text">
<string>Copy</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="cmdExport">
<property name="text">
<string>Export</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="cmdDelete">
<property name="text">
<string>Delete</string>
</property>
<property name="autoDefault">
<bool>true</bool>
</property>
<layout class="QHBoxLayout" name="hlSnapmatic">
<item>
<widget class="QCheckBox" name="cbSelected">
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="labPicture">
<property name="minimumSize">
<size>
<width>48</width>
<height>27</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>48</width>
<height>27</height>
</size>
</property>
<property name="lineWidth">
<number>0</number>
</property>
<property name="text">
<string/>
</property>
<property name="scaledContents">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="labPicStr">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>PHOTO - 00/00/00 00:00:00</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="cmdView">
<property name="text">
<string>View</string>
</property>
<property name="autoDefault">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="cmdCopy">
<property name="text">
<string>Copy</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="cmdExport">
<property name="text">
<string>Export</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="cmdDelete">
<property name="text">
<string>Delete</string>
</property>
<property name="autoDefault">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>