Browse Source

unfinished zoom support

1.10.x
Syping 1 year ago
parent
commit
4e004b1d68
  1. 159
      MapLocationDialog.cpp
  2. 11
      MapLocationDialog.h
  3. 15
      PictureDialog.cpp

159
MapLocationDialog.cpp

@ -48,8 +48,8 @@ MapLocationDialog::MapLocationDialog(double x, double y, QWidget *parent) :
ui->vlMapDialog->setSpacing(widgetMargin);
setMinimumSize(500 * screenRatio, 600 * screenRatio);
setMaximumSize(500 * screenRatio, 600 * screenRatio);
setMouseTracking(true);
zoomPercent = 100;
changeMode = false;
propUpdate = false;
}
@ -79,35 +79,12 @@ void MapLocationDialog::setCayoPerico(bool isCayoPerico)
ui->hlMapDialog->removeItem(ui->vlPosLayout);
ui->hlMapDialog->addLayout(ui->vlPosLayout);
ui->labPos->setAlignment(Qt::AlignRight);
mapImage = QImage(":/img/mapcayoperico.jpg");
}
drawPointOnMap(xpos_old, ypos_old);
}
void MapLocationDialog::on_cmdChange_clicked()
{
qreal screenRatio = AppEnv::screenRatio();
int pointMakerSize = 8 * screenRatio;
QPixmap pointMakerPixmap = IconLoader::loadingPointmakerIcon().pixmap(QSize(pointMakerSize, pointMakerSize));
QCursor pointMakerCursor(pointMakerPixmap);
ui->cmdDone->setVisible(true);
ui->cmdApply->setVisible(false);
ui->cmdChange->setVisible(false);
ui->cmdRevert->setVisible(false);
setCursor(pointMakerCursor);
changeMode = true;
}
void MapLocationDialog::on_cmdDone_clicked()
{
ui->cmdDone->setVisible(false);
ui->cmdChange->setVisible(true);
if (xpos_new != xpos_old || ypos_new != ypos_old) {
ui->cmdApply->setVisible(true);
ui->cmdRevert->setVisible(true);
else {
mapImage = QImage(":/img/mappreview.jpg");
}
setCursor(Qt::ArrowCursor);
changeMode = false;
drawPointOnMap(xpos_old, ypos_old);
}
void MapLocationDialog::updatePosFromEvent(double x, double y)
@ -134,19 +111,20 @@ void MapLocationDialog::updatePosFromEvent(double x, double y)
void MapLocationDialog::paintEvent(QPaintEvent *ev)
{
QPainter painter(this);
painter.setRenderHint(QPainter::SmoothPixmapTransform, true);
// Screen Ratio
qreal screenRatio = AppEnv::screenRatio();
qreal screenRatioPR = AppEnv::screenRatioPR();
// Paint Map
QImage mapImage;
if (p_isCayoPerico) {
mapImage = QImage(":/img/mapcayoperico.jpg");
}
else {
mapImage = QImage(":/img/mappreview.jpg");
}
painter.setRenderHint(QPainter::SmoothPixmapTransform, true);
painter.drawImage(QRect(QPoint(0, 0), size()), mapImage);
const double zoomLevel = static_cast<double>(zoomPercent) / 100;
const QSize mapImageSize = mapImage.size();
const QPointF mapImageMid(static_cast<double>(mapImageSize.width()) / 2, static_cast<double>(mapImageSize.height()) / 2);
const QSizeF srcImageSize(static_cast<double>(mapImageSize.width()) / zoomLevel , static_cast<double>(mapImageSize.height()) / zoomLevel);
const QPointF mapImageTopLeft(mapImageMid.x() - (srcImageSize.width() / 2), mapImageMid.y() - (srcImageSize.height() / 2));
const QPointF mapImageBottomRight(mapImageMid.x() + (srcImageSize.width() / 2), mapImageMid.y() + (srcImageSize.height() / 2));
painter.drawImage(QRect(QPoint(0, 0), size()), mapImage, QRectF(mapImageTopLeft, mapImageBottomRight));
// Paint Marker
QSize mapPixelSize = size();
@ -169,27 +147,24 @@ void MapLocationDialog::paintEvent(QPaintEvent *ev)
xpos_mp = xpos_per * mapPixelSize.width(); // locate window width pos
ypos_mp = ypos_per * mapPixelSize.height(); // locate window height pos
}
long xpos_pr, ypos_pr;
QPointF pointMarkerPos(xpos_mp, ypos_mp);
if (screenRatioPR != 1) {
xpos_pr = xpos_mp - pointMarkerHalfSize + screenRatioPR;
ypos_pr = ypos_mp - pointMarkerHalfSize + screenRatioPR;
pointMarkerPos.setX(pointMarkerPos.x() - pointMarkerHalfSize + screenRatioPR);
pointMarkerPos.setY(pointMarkerPos.y() - pointMarkerHalfSize + screenRatioPR);
}
else {
xpos_pr = xpos_mp - pointMarkerHalfSize;
ypos_pr = ypos_mp - pointMarkerHalfSize;
pointMarkerPos.setX(pointMarkerPos.x() - pointMarkerHalfSize);
pointMarkerPos.setY(pointMarkerPos.y() - pointMarkerHalfSize);
}
QPixmap mapMarkerPixmap = IconLoader::loadingPointmakerIcon().pixmap(QSize(pointMarkerSize, pointMarkerSize));
painter.drawPixmap(xpos_pr, ypos_pr, pointMarkerSize, pointMarkerSize, mapMarkerPixmap);
painter.drawPixmap(pointMarkerPos, mapMarkerPixmap);
QDialog::paintEvent(ev);
}
void MapLocationDialog::mouseMoveEvent(QMouseEvent *ev)
{
if (!changeMode) {
ev->ignore();
}
else if (ev->buttons() & Qt::LeftButton) {
if (changeMode && ev->buttons() & Qt::LeftButton) {
#if QT_VERSION >= 0x060000
const QPointF localPos = ev->position();
#elif QT_VERSION >= 0x050000
@ -208,19 +183,37 @@ void MapLocationDialog::mouseMoveEvent(QMouseEvent *ev)
#else
updatePosFromEvent(localPos.x(), localPos.y());
#endif
ev->accept();
}
else {
ev->ignore();
else if (dragStart && ev->buttons() & Qt::LeftButton) {
#if QT_VERSION >= 0x060000
const QPointF dragNewPosition = ev->position();
#elif QT_VERSION >= 0x050000
const QPointF dragNewPosition = ev->localPos();
#else
const QPointF dragNewPosition = ev->posF();
#endif
mapDiffPosition = dragNewPosition - dragPosition + mapDiffPosition;
dragPosition = dragNewPosition;
}
}
void MapLocationDialog::mouseReleaseEvent(QMouseEvent *ev)
void MapLocationDialog::mousePressEvent(QMouseEvent *ev)
{
if (!changeMode) {
ev->ignore();
if (!changeMode && ev->button() == Qt::LeftButton) {
#if QT_VERSION >= 0x060000
dragPosition = ev->position();
#elif QT_VERSION >= 0x050000
dragPosition = ev->localPos();
#else
dragPosition = ev->posF();
#endif
dragStart = true;
}
else if (ev->button() == Qt::LeftButton) {
}
void MapLocationDialog::mouseReleaseEvent(QMouseEvent *ev)
{
if (changeMode && ev->button() == Qt::LeftButton) {
#if QT_VERSION >= 0x060000
const QPointF localPos = ev->position();
#elif QT_VERSION >= 0x050000
@ -239,11 +232,63 @@ void MapLocationDialog::mouseReleaseEvent(QMouseEvent *ev)
#else
updatePosFromEvent(localPos.x(), localPos.y());
#endif
ev->accept();
}
else {
ev->ignore();
else if (dragStart && ev->button() == Qt::LeftButton) {
dragStart = false;
}
}
void MapLocationDialog::wheelEvent(QWheelEvent *ev)
{
const QPoint numPixels = ev->pixelDelta();
const QPoint numDegrees = ev->angleDelta();
if (!numPixels.isNull()) {
if (numPixels.y() < 0 && zoomPercent != 100) {
zoomPercent = zoomPercent - 10;
repaint();
}
else if (numPixels.y() > 0 && zoomPercent != 400) {
zoomPercent = zoomPercent + 10;
repaint();
}
}
else if (!numDegrees.isNull()) {
if (numDegrees.y() < 0 && zoomPercent != 100) {
zoomPercent = zoomPercent - 10;
repaint();
}
else if (numDegrees.y() > 0 && zoomPercent != 400) {
zoomPercent = zoomPercent + 10;
repaint();
}
}
}
void MapLocationDialog::on_cmdChange_clicked()
{
qreal screenRatio = AppEnv::screenRatio();
int pointMakerSize = 8 * screenRatio;
QPixmap pointMakerPixmap = IconLoader::loadingPointmakerIcon().pixmap(QSize(pointMakerSize, pointMakerSize));
QCursor pointMakerCursor(pointMakerPixmap);
ui->cmdDone->setVisible(true);
ui->cmdApply->setVisible(false);
ui->cmdChange->setVisible(false);
ui->cmdRevert->setVisible(false);
setCursor(pointMakerCursor);
changeMode = true;
}
void MapLocationDialog::on_cmdDone_clicked()
{
ui->cmdDone->setVisible(false);
ui->cmdChange->setVisible(true);
if (xpos_new != xpos_old || ypos_new != ypos_old) {
ui->cmdApply->setVisible(true);
ui->cmdRevert->setVisible(true);
}
setCursor(Qt::ArrowCursor);
changeMode = false;
}
void MapLocationDialog::on_cmdApply_clicked()

11
MapLocationDialog.h

@ -42,24 +42,31 @@ public:
protected:
void paintEvent(QPaintEvent *ev);
void mouseMoveEvent(QMouseEvent *ev);
void mousePressEvent(QMouseEvent *ev);
void mouseReleaseEvent(QMouseEvent *ev);
void wheelEvent(QWheelEvent *ev);
private slots:
void on_cmdDone_clicked();
void on_cmdApply_clicked();
void on_cmdDone_clicked();
void on_cmdClose_clicked();
void on_cmdChange_clicked();
void on_cmdRevert_clicked();
void updatePosFromEvent(double x, double y);
void on_cmdClose_clicked();
private:
int zoomPercent;
double xpos_old;
double ypos_old;
double xpos_new;
double ypos_new;
bool dragStart;
bool propUpdate;
bool changeMode;
bool p_isCayoPerico;
QImage mapImage;
QPointF dragPosition;
QPointF mapDiffPosition;
Ui::MapLocationDialog *ui;
};

15
PictureDialog.cpp

@ -305,17 +305,12 @@ void PictureDialog::styliseDialog()
}
#ifdef Q_OS_WIN
#if QT_VERSION >= 0x050000
#if QT_VERSION >= 0x060000
bool PictureDialog::nativeEvent(const QByteArray &eventType, void *message, qintptr *result)
{
MSG *msg = reinterpret_cast<MSG*>(message);
if (msg->message == 0x031e || msg->message == 0x0320) {
styliseDialog();
}
return QWidget::nativeEvent(eventType, message, result);
}
#elif QT_VERSION >= 0x050000
#else
bool PictureDialog::nativeEvent(const QByteArray &eventType, void *message, long *result)
#endif
{
MSG *msg = reinterpret_cast<MSG*>(message);
if (msg->message == 0x031e || msg->message == 0x0320) {
@ -411,11 +406,11 @@ bool PictureDialog::eventFilter(QObject *obj, QEvent *ev)
}
}
}
if (ev->type() == QEvent::MouseMove && dragStart) {
if (dragStart && ev->type() == QEvent::MouseMove) {
QMouseEvent *mouseEvent = dynamic_cast<QMouseEvent*>(ev);
if (mouseEvent->pos().y() <= layout()->menuBar()->height()) {
if (mouseEvent->buttons() & Qt::LeftButton) {
QPoint diff = mouseEvent->pos() - dragPosition;
const QPoint diff = mouseEvent->pos() - dragPosition;
move(QPoint(pos() + diff));
updateGeometry();
}

Loading…
Cancel
Save