Switched the method of how the Designer UI file is used in the DropBox class to "The Single Inheritance Approach" (with "Using a Pointer Member Variable"). This is the method which Qt recommends for large projects.

This commit is contained in:
LoRd_MuldeR 2012-12-11 22:51:18 +01:00
parent 04e9565d50
commit 7e96cd3fe5
2 changed files with 47 additions and 32 deletions

View File

@ -21,6 +21,8 @@
#include "Dialog_DropBox.h" #include "Dialog_DropBox.h"
#include "../tmp/UIC_DropBox.h"
#include "Global.h" #include "Global.h"
#include "Model_Settings.h" #include "Model_Settings.h"
@ -32,7 +34,7 @@
#include <QTimer> #include <QTimer>
#define EPS (1.0E-5) #define EPS (1.0E-5)
#define SET_FONT_BOLD(WIDGET,BOLD) { QFont _font = WIDGET.font(); _font.setBold(BOLD); WIDGET.setFont(_font); } #define SET_FONT_BOLD(WIDGET,BOLD) { QFont _font = (WIDGET)->font(); _font.setBold(BOLD); (WIDGET)->setFont(_font); }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Constructor // Constructor
@ -41,21 +43,25 @@
DropBox::DropBox(QWidget *parent, QAbstractItemModel *model, SettingsModel *settings) DropBox::DropBox(QWidget *parent, QAbstractItemModel *model, SettingsModel *settings)
: :
QDialog(parent, Qt::CustomizeWindowHint | Qt::WindowStaysOnTopHint), QDialog(parent, Qt::CustomizeWindowHint | Qt::WindowStaysOnTopHint),
m_counterLabel(this), ui(new Ui::DropBox),
m_model(model), m_model(model),
m_settings(settings), m_settings(settings),
m_moving(false), m_moving(false),
m_firstShow(true) m_firstShow(true)
{ {
//Init the dialog, from the .ui file //Init the dialog, from the .ui file
setupUi(this); ui->setupUi(this);
//Init counter //Init counter
m_counterLabel.setParent(dropBoxLabel); m_counterLabel = new QLabel(this);
m_counterLabel.setText("0"); m_counterLabel->setParent(ui->dropBoxLabel);
m_counterLabel.setAlignment(Qt::AlignHCenter | Qt::AlignTop); m_counterLabel->setText("0");
m_counterLabel->setAlignment(Qt::AlignHCenter | Qt::AlignTop);
SET_FONT_BOLD(m_counterLabel, true); SET_FONT_BOLD(m_counterLabel, true);
m_windowReferencePoint = new QPoint;
m_mouseReferencePoint = new QPoint;
//Prevent close //Prevent close
m_canClose = false; m_canClose = false;
@ -73,6 +79,10 @@ DropBox::DropBox(QWidget *parent, QAbstractItemModel *model, SettingsModel *sett
DropBox::~DropBox(void) DropBox::~DropBox(void)
{ {
LAMEXP_DELETE(m_counterLabel);
LAMEXP_DELETE(m_windowReferencePoint);
LAMEXP_DELETE(m_mouseReferencePoint);
LAMEXP_DELETE(ui);
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
@ -83,7 +93,7 @@ void DropBox::modelChanged(void)
{ {
if(m_model) if(m_model)
{ {
m_counterLabel.setText(QString::number(m_model->rowCount())); m_counterLabel->setText(QString::number(m_model->rowCount()));
} }
} }
@ -98,8 +108,8 @@ void DropBox::changeEvent(QEvent *e)
{ {
if(e->type() == QEvent::LanguageChange) if(e->type() == QEvent::LanguageChange)
{ {
Ui::DropBox::retranslateUi(this); ui->retranslateUi(this);
dropBoxLabel->setToolTip(QString("<b>%1</b><br><nobr>%2</nobr><br><nobr>%3</nobr>").arg(tr("LameXP DropBox"), tr("You can add files to LameXP via Drag&amp;Drop here!"), tr("(Right-click to close the DropBox)"))); ui->dropBoxLabel->setToolTip(QString("<b>%1</b><br><nobr>%2</nobr><br><nobr>%3</nobr>").arg(tr("LameXP DropBox"), tr("You can add files to LameXP via Drag&amp;Drop here!"), tr("(Right-click to close the DropBox)")));
} }
} }
@ -107,10 +117,10 @@ void DropBox::showEvent(QShowEvent *event)
{ {
QRect screenGeometry = QApplication::desktop()->availableGeometry(); QRect screenGeometry = QApplication::desktop()->availableGeometry();
resize(dropBoxLabel->pixmap()->size()); resize(ui->dropBoxLabel->pixmap()->size());
setMaximumSize(dropBoxLabel->pixmap()->size()); setMaximumSize(ui->dropBoxLabel->pixmap()->size());
m_counterLabel.setGeometry(0, dropBoxLabel->height() - 30, dropBoxLabel->width(), 25); m_counterLabel->setGeometry(0, ui->dropBoxLabel->height() - 30, ui->dropBoxLabel->width(), 25);
if(m_firstShow) if(m_firstShow)
{ {
@ -159,9 +169,9 @@ void DropBox::mousePressEvent(QMouseEvent *event)
} }
QApplication::setOverrideCursor(Qt::SizeAllCursor); QApplication::setOverrideCursor(Qt::SizeAllCursor);
*m_windowReferencePoint = this->pos();
*m_mouseReferencePoint = event->globalPos();
m_moving = true; m_moving = true;
m_windowReferencePoint = this->pos();
m_mouseReferencePoint = event->globalPos();
} }
void DropBox::mouseReleaseEvent(QMouseEvent *event) void DropBox::mouseReleaseEvent(QMouseEvent *event)
@ -183,13 +193,13 @@ void DropBox::mouseMoveEvent(QMouseEvent *event)
static const int magnetic = 22; static const int magnetic = 22;
QRect screenGeometry = QApplication::desktop()->availableGeometry(); QRect screenGeometry = QApplication::desktop()->availableGeometry();
const int delta_x = m_mouseReferencePoint.x() - event->globalX(); const int delta_x = m_mouseReferencePoint->x() - event->globalX();
const int delta_y = m_mouseReferencePoint.y() - event->globalY(); const int delta_y = m_mouseReferencePoint->y() - event->globalY();
const int max_x = screenGeometry.width() - frameGeometry().width() + screenGeometry.left(); const int max_x = screenGeometry.width() - frameGeometry().width() + screenGeometry.left();
const int max_y = screenGeometry.height() - frameGeometry().height() + screenGeometry.top(); const int max_y = screenGeometry.height() - frameGeometry().height() + screenGeometry.top();
int new_x = qMin(max_x, qMax(screenGeometry.left(), m_windowReferencePoint.x() - delta_x)); int new_x = qMin(max_x, qMax(screenGeometry.left(), m_windowReferencePoint->x() - delta_x));
int new_y = qMin(max_y, qMax(screenGeometry.top(), m_windowReferencePoint.y() - delta_y)); int new_y = qMin(max_y, qMax(screenGeometry.top(), m_windowReferencePoint->y() - delta_y));
if(new_x < magnetic) if(new_x < magnetic)
{ {
@ -214,7 +224,7 @@ void DropBox::mouseMoveEvent(QMouseEvent *event)
void DropBox::showToolTip(void) void DropBox::showToolTip(void)
{ {
QToolTip::showText(dropBoxLabel->mapToGlobal(dropBoxLabel->pos()), dropBoxLabel->toolTip()); QToolTip::showText(ui->dropBoxLabel->mapToGlobal(ui->dropBoxLabel->pos()), ui->dropBoxLabel->toolTip());
} }
bool DropBox::event(QEvent *event) bool DropBox::event(QEvent *event)

View File

@ -21,20 +21,23 @@
#pragma once #pragma once
#include "../tmp/UIC_DropBox.h" #include <QDialog>
#include <QPoint> //UIC forward declartion
namespace Ui {
class DropBox;
}
class QDragEnterEvent; //Class declarations
class QMouseEvent;
class QAbstractItemModel; class QAbstractItemModel;
class QDragEnterEvent;
class QLabel;
class QMouseEvent;
class QPoint;
class SettingsModel; class SettingsModel;
//////////////////////////////////////////////////////////// //DropBox class
// Splash Frame class DropBox: public QDialog
////////////////////////////////////////////////////////////
class DropBox: public QDialog, private Ui::DropBox
{ {
Q_OBJECT Q_OBJECT
@ -43,10 +46,12 @@ public:
~DropBox(void); ~DropBox(void);
private: private:
Ui::DropBox *ui; //for Qt UIC
bool m_canClose; bool m_canClose;
QPoint m_mouseReferencePoint; QPoint *m_mouseReferencePoint;
QPoint m_windowReferencePoint; QPoint *m_windowReferencePoint;
QLabel m_counterLabel; QLabel *m_counterLabel;
QAbstractItemModel *m_model; QAbstractItemModel *m_model;
SettingsModel *m_settings; SettingsModel *m_settings;
bool m_moving; bool m_moving;