From ea2b9046e73d789035845bdffbb7f10deb92f6b0 Mon Sep 17 00:00:00 2001 From: Rafael Date: Fri, 1 Apr 2016 19:32:16 +0200 Subject: [PATCH] add modifed QLabel as UiModLabel, ProfileInterface widgets are now in QMap --- PictureDialog.ui | 15 ++++++++++- ProfileInterface.cpp | 12 ++++----- ProfileInterface.h | 3 ++- gta5sync.pro | 6 +++-- uimod/UiModLabel.cpp | 61 ++++++++++++++++++++++++++++++++++++++++++++ uimod/UiModLabel.h | 48 ++++++++++++++++++++++++++++++++++ 6 files changed, 135 insertions(+), 10 deletions(-) create mode 100755 uimod/UiModLabel.cpp create mode 100755 uimod/UiModLabel.h diff --git a/PictureDialog.ui b/PictureDialog.ui index 510b176..62ce0b5 100755 --- a/PictureDialog.ui +++ b/PictureDialog.ui @@ -27,7 +27,7 @@ 0 - + @@ -110,6 +110,19 @@ + + + UiModLabel + QLabel +
uimod/UiModLabel.h
+ + mouseMoved() + mouseReleased() + mousePressed() + mouseDoubleClicked() + +
+
diff --git a/ProfileInterface.cpp b/ProfileInterface.cpp index 1bc881d..c5fbae0 100755 --- a/ProfileInterface.cpp +++ b/ProfileInterface.cpp @@ -66,9 +66,9 @@ ProfileInterface::~ProfileInterface() picture->deleteLater(); delete picture; } - foreach(QWidget *widget, widgets) + foreach(QWidget *widget, widgets.keys()) { - widgets.removeAll(widget); + widgets.remove(widget); widget->deleteLater(); delete widget; } @@ -99,7 +99,7 @@ void ProfileInterface::on_savegameLoaded(SavegameData *savegame, QString savegam SavegameWidget *sgdWidget = new SavegameWidget(); sgdWidget->setSavegameData(savegame, savegamePath); ui->vlSavegame->addWidget(sgdWidget); - widgets.append(sgdWidget); + widgets[sgdWidget] = "SavegameWidget"; savegames.append(savegame); QObject::connect(sgdWidget, SIGNAL(savegameDeleted()), this, SLOT(on_savegameDeleted())); } @@ -109,7 +109,7 @@ void ProfileInterface::on_pictureLoaded(SnapmaticPicture *picture, QString pictu SnapmaticWidget *picWidget = new SnapmaticWidget(profileDB, threadDB); picWidget->setSnapmaticPicture(picture, picturePath); ui->vlSnapmatic->addWidget(picWidget); - widgets.append(picWidget); + widgets[picWidget] = "SnapmaticWidget"; pictures.append(picture); QObject::connect(picWidget, SIGNAL(pictureDeleted()), this, SLOT(on_pictureDeleted())); } @@ -133,7 +133,7 @@ void ProfileInterface::on_profileLoaded() void ProfileInterface::on_savegameDeleted() { SavegameWidget *sgdWidget = (SavegameWidget*)sender(); - widgets.removeAll(sgdWidget); + widgets.remove(sgdWidget); sgdWidget->deleteLater(); delete sgdWidget; } @@ -141,7 +141,7 @@ void ProfileInterface::on_savegameDeleted() void ProfileInterface::on_pictureDeleted() { SnapmaticWidget *picWidget = (SnapmaticWidget*)sender(); - widgets.removeAll(picWidget); + widgets.remove(picWidget); picWidget->deleteLater(); delete picWidget; } diff --git a/ProfileInterface.h b/ProfileInterface.h index 5d09a30..8083f82 100755 --- a/ProfileInterface.h +++ b/ProfileInterface.h @@ -29,6 +29,7 @@ #include #include #include +#include namespace Ui { class ProfileInterface; @@ -62,7 +63,7 @@ private: ProfileLoader *profileLoader; QList savegames; QList pictures; - QList widgets; + QMap widgets; QSpacerItem *saSpacerItem; QString profileFolder; QString profileName; diff --git a/gta5sync.pro b/gta5sync.pro index aeac13b..d071c71 100755 --- a/gta5sync.pro +++ b/gta5sync.pro @@ -40,7 +40,8 @@ SOURCES += main.cpp \ SnapmaticWidget.cpp \ StandardPaths.cpp \ StringParser.cpp \ - UserInterface.cpp + UserInterface.cpp \ + uimod/UiModLabel.cpp HEADERS += \ AboutDialog.h \ @@ -59,7 +60,8 @@ HEADERS += \ SnapmaticWidget.h \ StandardPaths.h \ StringParser.h \ - UserInterface.h + UserInterface.h \ + uimod/UiModLabel.h FORMS += \ AboutDialog.ui \ diff --git a/uimod/UiModLabel.cpp b/uimod/UiModLabel.cpp new file mode 100755 index 0000000..d0fcfd0 --- /dev/null +++ b/uimod/UiModLabel.cpp @@ -0,0 +1,61 @@ +/***************************************************************************** +* gta5sync GRAND THEFT AUTO V SYNC +* Copyright (C) 2016 Syping +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see . +*****************************************************************************/ + +#include "UiModLabel.h" + +UiModLabel::UiModLabel(const QString &text, QWidget *parent) : QLabel(parent) +{ + setText(text); +} + +UiModLabel::UiModLabel(QWidget *parent, const QString &text) : QLabel(parent) +{ + setText(text); +} + +UiModLabel::UiModLabel(QWidget *parent) : QLabel(parent) +{ +} + +UiModLabel::~UiModLabel() +{ +} + +void UiModLabel::mouseMoveEvent(QMouseEvent *ev) +{ + QLabel::mouseMoveEvent(ev); + emit mouseMoved(); +} + +void UiModLabel::mousePressEvent(QMouseEvent *ev) +{ + QLabel::mousePressEvent(ev); + emit mousePressed(); +} + +void UiModLabel::mouseReleaseEvent(QMouseEvent *ev) +{ + QLabel::mouseReleaseEvent(ev); + emit mouseReleased(); +} + +void UiModLabel::mouseDoubleClickEvent(QMouseEvent *ev) +{ + QLabel::mouseDoubleClickEvent(ev); + emit mouseDoubleClicked(); +} diff --git a/uimod/UiModLabel.h b/uimod/UiModLabel.h new file mode 100755 index 0000000..03f9fe0 --- /dev/null +++ b/uimod/UiModLabel.h @@ -0,0 +1,48 @@ +/***************************************************************************** +* gta5sync GRAND THEFT AUTO V SYNC +* Copyright (C) 2016 Syping +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see . +*****************************************************************************/ + +#ifndef UIMODLABEL_H +#define UIMODLABEL_H + +#include +#include +#include + +class UiModLabel : public QLabel +{ + Q_OBJECT +public: + UiModLabel(const QString &text, QWidget *parent = 0); + UiModLabel(QWidget *parent, const QString &text); + UiModLabel(QWidget *parent = 0); + ~UiModLabel(); + +protected: + void mouseMoveEvent(QMouseEvent *ev); + void mousePressEvent(QMouseEvent *ev); + void mouseReleaseEvent(QMouseEvent *ev); + void mouseDoubleClickEvent(QMouseEvent *ev); + +signals: + void mouseMoved(); + void mousePressed(); + void mouseReleased(); + void mouseDoubleClicked(); +}; + +#endif // UIMODLABEL_H