Permalink
Browse files

First upload

  • Loading branch information...
rexchen80 committed Dec 27, 2013
1 parent f8d12b0 commit b4d39d768ed7ae6de7a16756a06ab59fe65e4b09
Showing 5,423 changed files with 1,116,470 additions and 0 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
View
@@ -0,0 +1,127 @@
#include "AffirmForm.h"
#include <QMouseEvent>
#include <QPainter>
AffirmForm::AffirmForm(const QRect rect, QWidget *parent)
: QWidget(parent)
, rect_(rect)
, pParent_(parent)
{
setupUi(this);
initData();
initGui();
}
void AffirmForm::changeEvent(QEvent *e)
{
QWidget::changeEvent(e);
switch (e->type()) {
case QEvent::LanguageChange:
retranslateUi(this);
break;
default:
break;
}
}
void AffirmForm::paintEvent(QPaintEvent *event)
{
QStyleOption opt;
opt.init(this);
QPainter p(this);
style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this);
}
void AffirmForm::showEvent(QShowEvent *)
{
this->setGeometry(rect_);
}
bool AffirmForm::eventFilter(QObject *target, QEvent *event)
{
if(target == labelBack
|| target == labelNotSave
|| target == labelSave)
{
if(QEvent::MouseButtonPress == event->type())
{
QMouseEvent *mouseEvent = static_cast<QMouseEvent *>(event);
if(Qt::LeftButton == mouseEvent->button())
{
//先处理哪一个按下
if(target == labelBack)
{
emit signalBack();
}
else if(target == labelNotSave)
{
emit signalNotSave();
}
else if(target == labelSave)
{
emit signalSave();
}
//获取屏幕左上角坐标与软件左上角坐标的偏移
this->mousePressEvent(mouseEvent);
return true;
}
}
else if (QEvent::MouseMove == event->type())
{
QMouseEvent *mouseEvent = static_cast<QMouseEvent *>(event);
this->mouseMoveEvent(mouseEvent);
return true;
}
else
{
#ifdef Q_OS_WIN32
QWidget::eventFilter(target, event);
#else
return false;
#endif
}
}
else
{
return QWidget::eventFilter(target, event);
}
}
void AffirmForm::mousePressEvent(QMouseEvent *event)
{
if (event->button() == Qt::LeftButton)
{
QWidget *pParent_ = static_cast<QWidget *>(this->parent());
if(NULL == pParent_)
{
return;
}
offset_ = event->globalPos() - pParent_->frameGeometry().topLeft();
}
}
void AffirmForm::mouseMoveEvent(QMouseEvent *event)
{
if (!(event->buttons() & Qt::LeftButton))
{
return;
}
if ((event->pos() - offset_).manhattanLength()
< QApplication::startDragDistance())
{
return;
}
pParent_->move(event->globalPos() - offset_);
}
void AffirmForm::initData()
{
labelBack->installEventFilter(this);
labelNotSave->installEventFilter(this);
labelSave->installEventFilter(this);
}
void AffirmForm::initGui()
{
move(1, 1);
}
View
@@ -0,0 +1,36 @@
#ifndef AFFIRMFORM_H
#define AFFIRMFORM_H
#include "ui_AffirmForm.h"
class AffirmForm : public QWidget, private Ui::AffirmForm
{
Q_OBJECT
public:
explicit AffirmForm(const QRect rect, QWidget *parent = 0);
signals:
void signalBack();
void signalNotSave();
void signalSave();
protected:
void changeEvent(QEvent *e);
void paintEvent(QPaintEvent *event);
void showEvent(QShowEvent *);
bool eventFilter(QObject *target, QEvent *event);
void mousePressEvent(QMouseEvent *event);
void mouseMoveEvent(QMouseEvent *event);
private:
void initData();
void initGui();
private:
QRect rect_;
QPoint offset_;
QWidget *pParent_;
};
#endif // AFFIRMFORM_H
Oops, something went wrong.

0 comments on commit b4d39d7

Please sign in to comment.