Merge branch 'v101-0523' into 'yhkylin/v101'
Gbp-Pq: Name 0004-Merge-branch-v101-0523-into-yhkylin-v101.patch
This commit is contained in:
parent
52181d2296
commit
44c0f4cfb9
|
@ -1,6 +1,9 @@
|
|||
#include "lockslider.h"
|
||||
#include <QPainter>
|
||||
#include <QToolTip>
|
||||
#include <QEvent>
|
||||
#include <QMouseEvent>
|
||||
#include <QDebug>
|
||||
|
||||
static const int node_radius = 5;
|
||||
static const int handle_radius = 8;
|
||||
|
@ -13,6 +16,7 @@ LockSlider::LockSlider(QStringList list, QWidget *parent) :
|
|||
this->setMinimumHeight(50);
|
||||
this->setMaximumHeight(100);
|
||||
this->installEventFilter(this);
|
||||
mouseLeftBtnIsPressed = false;
|
||||
}
|
||||
|
||||
LockSlider::~LockSlider()
|
||||
|
@ -96,7 +100,7 @@ bool LockSlider::eventFilter(QObject *watched, QEvent *event)
|
|||
{
|
||||
if (watched == this) {
|
||||
QMouseEvent *me = static_cast<QMouseEvent*>(event);
|
||||
if (event->type() == QEvent::HoverMove) {
|
||||
if (event->type() == QEvent::HoverMove && !mouseLeftBtnIsPressed) {
|
||||
initNodePoint();
|
||||
QPoint mousePos = me->pos();
|
||||
for (int i = 0; i < nodePointList.size(); ++i) {
|
||||
|
@ -106,11 +110,10 @@ bool LockSlider::eventFilter(QObject *watched, QEvent *event)
|
|||
radius = handle_radius;
|
||||
}
|
||||
if (isContains(mousePos, point, radius)) {
|
||||
this->setToolTip(scaleList.at(i));
|
||||
showTooltip(i);
|
||||
break;
|
||||
} else {
|
||||
if (i == nodePointList.size() - 1) {
|
||||
this->setToolTip("");
|
||||
QToolTip::hideText();
|
||||
}
|
||||
}
|
||||
|
@ -127,3 +130,60 @@ bool LockSlider::isContains(QPoint p1, QPoint p2, int radius)
|
|||
&& p2.y() - radius <= p1.y()
|
||||
&& p2.y() + radius >= p1.y());
|
||||
}
|
||||
|
||||
void LockSlider::mousePressEvent(QMouseEvent *e)
|
||||
{
|
||||
KSlider::mousePressEvent(e);
|
||||
initNodePoint();
|
||||
if (e->button() == Qt::LeftButton) {
|
||||
mouseLeftBtnIsPressed = true;
|
||||
showTooltip(this->value() - 1);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
void LockSlider::mouseReleaseEvent(QMouseEvent *e)
|
||||
{
|
||||
KSlider::mouseReleaseEvent(e);
|
||||
if (e->button() == Qt::LeftButton) {
|
||||
mouseLeftBtnIsPressed = false;
|
||||
showTooltip(this->value() - 1);
|
||||
QPoint mousePos = e->pos();
|
||||
for (int i = 0; i < nodePointList.size(); ++i) {
|
||||
QPoint point = nodePointList.at(i);
|
||||
int radius = node_radius;
|
||||
if (this->value() == i + 1) {
|
||||
radius = handle_radius;
|
||||
}
|
||||
if (isContains(mousePos, point, radius)) {
|
||||
break;
|
||||
} else {
|
||||
if (i == nodePointList.size() - 1) {
|
||||
QToolTip::hideText();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
void LockSlider::mouseMoveEvent(QMouseEvent *e)
|
||||
{
|
||||
KSlider::mouseMoveEvent(e);
|
||||
if (e->buttons() & Qt::LeftButton) {
|
||||
showTooltip(this->value() - 1);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
void LockSlider::showTooltip(const int &num)
|
||||
{
|
||||
initNodePoint();
|
||||
int textLeftMargin = 8;
|
||||
int textTopMargin = 12;
|
||||
QPoint m_point = this->mapToGlobal(nodePointList.at(num));
|
||||
QFontMetrics fontMetrics = QFontMetrics(this->font());
|
||||
QRect fontRect = fontMetrics.boundingRect(scaleList.at(num));
|
||||
QToolTip::showText(m_point - QPoint(fontRect.width()/2 + textLeftMargin, 20 + textTopMargin*2 + fontRect.height()), scaleList.at(num));
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -14,14 +14,19 @@ public:
|
|||
~LockSlider();
|
||||
void initNodePoint();
|
||||
bool isContains(QPoint p1, QPoint p2, int radius);
|
||||
void showTooltip(const int &num);
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent *e);
|
||||
bool eventFilter(QObject *watched, QEvent *event);
|
||||
void mousePressEvent(QMouseEvent *e);
|
||||
void mouseReleaseEvent(QMouseEvent *e);
|
||||
void mouseMoveEvent(QMouseEvent *e);
|
||||
|
||||
private:
|
||||
QStringList scaleList;
|
||||
QList<QPoint>nodePointList;
|
||||
bool mouseLeftBtnIsPressed;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -65,6 +65,12 @@ void PictureLabel::paintEvent(QPaintEvent *e)
|
|||
break;
|
||||
}
|
||||
}
|
||||
} else if (mode == "zoom") {
|
||||
p.drawPixmap(getDestRect(pixmap), pixmap, pixmap.rect());
|
||||
} else if (mode == "spanned") {
|
||||
p.drawPixmap(this->rect(), pixmap, getSourceRect(pixmap, this->geometry()));
|
||||
} else {
|
||||
p.drawPixmap(rect().adjusted(0, 0, 0, 0), pixmap, pixmap.rect());
|
||||
}
|
||||
p.restore();
|
||||
}
|
||||
|
@ -124,7 +130,6 @@ QRect PictureLabel::getSourceRect(const QPixmap &pixmap)
|
|||
|
||||
QPoint offsetPoint = pixmap.rect().topLeft();
|
||||
offsetPoint += QPoint(offsetX, offsetY);
|
||||
|
||||
return QRect(offsetPoint, sourceSize);
|
||||
}
|
||||
|
||||
|
@ -150,6 +155,48 @@ QRect PictureLabel::getSourceRect(const QPixmap &pixmap, const QRect &screenGeom
|
|||
|
||||
QPoint offsetPoint = pixmap.rect().topLeft();
|
||||
offsetPoint += QPoint(offsetX, offsetY);
|
||||
return QRect(offsetPoint, sourceSize);
|
||||
}
|
||||
|
||||
QRect PictureLabel::getDestRect(const QPixmap &pixmap)
|
||||
{
|
||||
qreal screenScale = qreal(this->rect().width()) / qreal(this->rect().height());
|
||||
qreal pixmapScale = qreal(pixmap.width() / pixmap.height());
|
||||
qreal width = pixmap.width();
|
||||
qreal height = pixmap.height();
|
||||
|
||||
if (pixmapScale == screenScale) {
|
||||
return this->rect();
|
||||
}
|
||||
|
||||
qreal scaleWidth = this->rect().width() / width;
|
||||
qreal scaleHeight = this->rect().height() / height;
|
||||
qreal realPixmapWidth = 0;
|
||||
qreal realPixmapHeight = 0;
|
||||
|
||||
if(pixmapScale < screenScale){
|
||||
//图片比例小于屏幕比例时,按照图片和屏幕高度比进行缩放
|
||||
realPixmapWidth = width * scaleHeight;
|
||||
realPixmapHeight = this->rect().height();
|
||||
}else{
|
||||
//图片比例大于屏幕比例时,按照图片与屏幕宽度比进行缩放
|
||||
realPixmapWidth = this->rect().width();
|
||||
realPixmapHeight = height * scaleWidth;
|
||||
}
|
||||
|
||||
QSize sourceSize = this->size();
|
||||
qint32 offsetX = 0;
|
||||
qint32 offsetY = 0;
|
||||
if (this->rect().width() == realPixmapWidth) {
|
||||
offsetY = (this->rect().height() - realPixmapHeight) / 2;
|
||||
sourceSize.setHeight(realPixmapHeight);
|
||||
} else if (this->rect().height() == realPixmapHeight) {
|
||||
offsetX = (this->rect().width() - realPixmapWidth) / 2;
|
||||
sourceSize.setWidth(realPixmapWidth);
|
||||
}
|
||||
|
||||
QPoint offsetPoint = this->rect().topLeft();
|
||||
offsetPoint += QPoint(offsetX, offsetY);
|
||||
|
||||
return QRect(offsetPoint, sourceSize);
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@ public:
|
|||
void setLocalPixmap(QPixmap pixmap);
|
||||
QRect getSourceRect(const QPixmap &pixmap, const QRect &screenGeometry);
|
||||
QRect getSourceRect(const QPixmap &pixmap);
|
||||
QRect getDestRect(const QPixmap &pixmap);
|
||||
void setMode(QString mode);
|
||||
|
||||
protected:
|
||||
|
|
Loading…
Reference in New Issue