From f5d23962560707af4e1171761ef848a197542d3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Lemaire?= Date: Wed, 27 Jun 2012 09:48:55 +0000 Subject: [PATCH] paysages : Added a tooltip for preview OSD items. git-svn-id: https://subversion.assembla.com/svn/thunderk/paysages@363 b1fd45b6-86a6-48da-8261-f70d1f35bdcc --- TODO | 1 - gui_qt/basepreview.cpp | 45 +++++++++++++++++++++++++++++++++----- gui_qt/basepreview.h | 4 ++++ gui_qt/mainwindow.cpp | 4 +++- gui_qt/previewosd.cpp | 31 ++++++++++++++++++++++++++ gui_qt/previewosd.h | 5 +++++ i18n/paysages_fr.ts | 49 +++++++++++++++++++++++------------------- 7 files changed, 110 insertions(+), 29 deletions(-) diff --git a/TODO b/TODO index 61492b0..8052cfa 100644 --- a/TODO +++ b/TODO @@ -17,7 +17,6 @@ Technology Preview 2 : - Improve previews. => Add a right click menu for toggles and modes => Add user markers on OSD - => Add a tooltip for OSD items - Add a zone editor dialog for localized textures. - Add a terrain modifier dialog with zones. - Use the curve editor in noise editor diff --git a/gui_qt/basepreview.cpp b/gui_qt/basepreview.cpp index 9c621fe..4a09383 100644 --- a/gui_qt/basepreview.cpp +++ b/gui_qt/basepreview.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include "tools.h" /*************** PreviewChunk ***************/ @@ -276,6 +277,10 @@ QWidget(parent) _width = width(); _height = height(); _revision = 0; + + _info = new QLabel(this); + _info->setVisible(false); + _info->setStyleSheet("QLabel { background-color: white; color: black; }"); this->alive = true; @@ -293,6 +298,7 @@ BasePreview::~BasePreview() _drawing_manager->removeChunks(this); + delete _info; delete pixbuf; delete lock_drawing; } @@ -300,6 +306,7 @@ BasePreview::~BasePreview() void BasePreview::addOsd(QString name) { _osd.append(PreviewOsd::getInstance(name)); + setMouseTracking(true); } void BasePreview::initDrawers() @@ -502,12 +509,16 @@ void BasePreview::mousePressEvent(QMouseEvent* event) void BasePreview::mouseMoveEvent(QMouseEvent* event) { - int dx, dy; - int ndx, ndy; int width, height; + + width = this->width(); + height = this->height(); if (event->buttons() & Qt::LeftButton) { + int dx, dy; + int ndx, ndy; + dx = event->x() - mousex; dy = event->y() - mousey; @@ -531,9 +542,6 @@ void BasePreview::mouseMoveEvent(QMouseEvent* event) } if (ndx != 0 || ndy != 0) { - width = this->width(); - height = this->height(); - if (ndx <= -width || ndx >= width || ndy <= -height || ndy >= height) { xoffset -= (double) ndx * scaling; @@ -589,6 +597,28 @@ void BasePreview::mouseMoveEvent(QMouseEvent* event) mousex = event->x(); mousey = event->y(); } + else + { + // Get text info from OSD + bool found = false; + for (int i = 0; i < _osd.size(); i++) + { + double x = xoffset + (event->x() - width / 2) * scaling; + double y = yoffset + (event->y() - height / 2) * scaling; + QString info = _osd[i]->getToolTip(x, y, scaling); + if (not info.isEmpty()) + { + _info->setText(info); + _info->setVisible(true); + found = true; + break; + } + } + if (not found) + { + _info->setVisible(false); + } + } } void BasePreview::wheelEvent(QWheelEvent* event) @@ -676,3 +706,8 @@ void BasePreview::wheelEvent(QWheelEvent* event) event->accept(); } + +void BasePreview::leaveEvent(QEvent* event) +{ + _info->setVisible(false); +} diff --git a/gui_qt/basepreview.h b/gui_qt/basepreview.h index d6e70d2..169b529 100644 --- a/gui_qt/basepreview.h +++ b/gui_qt/basepreview.h @@ -7,6 +7,7 @@ #include #include #include +#include #include "previewosd.h" class BasePreview : public QWidget { @@ -52,10 +53,13 @@ private: void mousePressEvent(QMouseEvent* event); void mouseMoveEvent(QMouseEvent* event); void wheelEvent(QWheelEvent* event); + void leaveEvent(QEvent* event); QMutex* lock_drawing; QImage* pixbuf; QVector _osd; + + QLabel* _info; int _width; int _height; diff --git a/gui_qt/mainwindow.cpp b/gui_qt/mainwindow.cpp index 9f2b557..9b3d91f 100644 --- a/gui_qt/mainwindow.cpp +++ b/gui_qt/mainwindow.cpp @@ -157,7 +157,9 @@ void MainWindow::refreshAll() PreviewOsd* osd = PreviewOsd::getInstance(QString("geolocation")); osd->clearItems(); sceneryGetCamera(&camera); - osd->newItem(50, 50)->drawCamera(&camera); + PreviewOsdItem* item = osd->newItem(50, 50); + item->drawCamera(&camera); + item->setToolTip(QString(tr("Camera"))); cameraDeleteDefinition(&camera); } diff --git a/gui_qt/previewosd.cpp b/gui_qt/previewosd.cpp index ebf7e81..b70a481 100644 --- a/gui_qt/previewosd.cpp +++ b/gui_qt/previewosd.cpp @@ -35,6 +35,23 @@ void PreviewOsdItem::drawCamera(CameraDefinition* camera) painter.drawLine(w2, h2, w2 + w2 * cos(camera->yaw + M_PI_4), h2 - h2 * sin(camera->yaw + M_PI_4)); } +void PreviewOsdItem::setToolTip(QString text) +{ + _tooltip = text; +} + +QString PreviewOsdItem::getToolTip(double x, double y, double scaling) +{ + if (_tooltip.isEmpty() or (x > _xlocation - (width() / 2) * scaling and x < _xlocation + (width() / 2) * scaling and y > _ylocation - (height() / 2) * scaling and y < _ylocation + (height() / 2) * scaling)) + { + return _tooltip; + } + else + { + return QString(); + } +} + /*************** PreviewOsd ***************/ PreviewOsd::PreviewOsd() { @@ -98,3 +115,17 @@ void PreviewOsd::apply(QImage* mask, double xoffset, double yoffset, double scal painter.drawImage(x, y, *item); } } + +QString PreviewOsd::getToolTip(double x, double y, double scaling) +{ + for (int i = 0; i < _items.size(); i++) + { + PreviewOsdItem* item = _items[i]; + QString tooltip = item->getToolTip(x, y, scaling); + if (not tooltip.isEmpty()) + { + return tooltip; + } + } + return QString(); +} diff --git a/gui_qt/previewosd.h b/gui_qt/previewosd.h index cae5d7d..43b1bce 100644 --- a/gui_qt/previewosd.h +++ b/gui_qt/previewosd.h @@ -13,11 +13,15 @@ public: inline double xlocation() {return _xlocation;}; inline double ylocation() {return _ylocation;}; + void setToolTip(QString text); + QString getToolTip(double x, double y, double scaling); + void drawCamera(CameraDefinition* camera); private: double _xlocation; double _ylocation; + QString _tooltip; }; class PreviewOsd @@ -32,6 +36,7 @@ public: PreviewOsdItem* newItem(int width, int height); PreviewOsdItem* newItem(QImage image); void apply(QImage* mask, double xoffset, double yoffset, double scaling); + QString getToolTip(double x, double y, double scaling); private: QVector _items; diff --git a/i18n/paysages_fr.ts b/i18n/paysages_fr.ts index 8c40df9..22c831f 100644 --- a/i18n/paysages_fr.ts +++ b/i18n/paysages_fr.ts @@ -1007,87 +1007,92 @@ rapide (F5) F5 - + + Camera + Caméra + + + Do you want to start a new scenery ? Any unsaved changes will be lost. Voulez-vous commencer un nouveau paysage ? Les modifications non sauvegardées seront perdues. - + Paysages 3D - New scenery Paysages 3D - Nouvelle scène - + Paysages 3D - Choose a file to save the scenery Paysages 3D - Choisissez un fichier pour enregistrer la scène - - + + Paysages 3D Scenery (*.p3d) Scène Paysages 3D (*.p3d) - - + + Paysages 3D - File saving error - + Can't write specified file : %1 - + Unexpected error while saving file : %1 - + Do you want to load a scenery from file ? Any unsaved changes will be lost. Voulez-vous charger une scène ? Les modifications non sauvegardées seront perdues. - + Paysages 3D - Load scenery Paysages 3D - Charger une scène - + Paysages 3D - Choose a scenery file to load Paysages 3D - Choisissez un fichier de scène à charger - - - - + + + + Paysages 3D - File loading error - + Can't read specified file : %1 - + This file doesn't look like a Paysages 3D file : %1 - + This file was created with an incompatible Paysages 3D version : %1 - + Unexpected error while loading file : %1 - + A 3D landscape editing and rendering software. Authors : @@ -1197,7 +1202,7 @@ GLib - http://www.gtk.org/ Voulez-vous charger un paysage ? Les modifications nons sauvegardées seront perdues. - + Paysages 3D Paysages 3D