paysages : Added a tooltip for preview OSD items.

git-svn-id: https://subversion.assembla.com/svn/thunderk/paysages@363 b1fd45b6-86a6-48da-8261-f70d1f35bdcc
This commit is contained in:
Michaël Lemaire 2012-06-27 09:48:55 +00:00 committed by ThunderK
parent b1ae9394d2
commit f5d2396256
7 changed files with 110 additions and 29 deletions

1
TODO
View file

@ -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

View file

@ -5,6 +5,7 @@
#include <QPainter>
#include <QTimer>
#include <QWheelEvent>
#include <qt4/QtGui/qlabel.h>
#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);
}

View file

@ -7,6 +7,7 @@
#include <QThread>
#include <QVector>
#include <QList>
#include <QLabel>
#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<PreviewOsd*> _osd;
QLabel* _info;
int _width;
int _height;

View file

@ -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);
}

View file

@ -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();
}

View file

@ -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<PreviewOsdItem*> _items;

View file

@ -1007,87 +1007,92 @@ rapide (F5)</translation>
<translation>F5</translation>
</message>
<message>
<location filename="../gui_qt/mainwindow.cpp" line="166"/>
<location filename="../gui_qt/mainwindow.cpp" line="162"/>
<source>Camera</source>
<translation type="unfinished">Caméra</translation>
</message>
<message>
<location filename="../gui_qt/mainwindow.cpp" line="168"/>
<source>Do you want to start a new scenery ? Any unsaved changes will be lost.</source>
<translation>Voulez-vous commencer un nouveau paysage ? Les modifications non sauvegardées seront perdues.</translation>
</message>
<message>
<location filename="../gui_qt/mainwindow.cpp" line="166"/>
<location filename="../gui_qt/mainwindow.cpp" line="168"/>
<source>Paysages 3D - New scenery</source>
<translation>Paysages 3D - Nouvelle scène</translation>
</message>
<message>
<location filename="../gui_qt/mainwindow.cpp" line="176"/>
<location filename="../gui_qt/mainwindow.cpp" line="178"/>
<source>Paysages 3D - Choose a file to save the scenery</source>
<translation>Paysages 3D - Choisissez un fichier pour enregistrer la scène</translation>
</message>
<message>
<location filename="../gui_qt/mainwindow.cpp" line="176"/>
<location filename="../gui_qt/mainwindow.cpp" line="202"/>
<location filename="../gui_qt/mainwindow.cpp" line="178"/>
<location filename="../gui_qt/mainwindow.cpp" line="204"/>
<source>Paysages 3D Scenery (*.p3d)</source>
<translation>Scène Paysages 3D (*.p3d)</translation>
</message>
<message>
<location filename="../gui_qt/mainwindow.cpp" line="190"/>
<location filename="../gui_qt/mainwindow.cpp" line="193"/>
<location filename="../gui_qt/mainwindow.cpp" line="192"/>
<location filename="../gui_qt/mainwindow.cpp" line="195"/>
<source>Paysages 3D - File saving error</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../gui_qt/mainwindow.cpp" line="190"/>
<location filename="../gui_qt/mainwindow.cpp" line="192"/>
<source>Can&apos;t write specified file : %1</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../gui_qt/mainwindow.cpp" line="193"/>
<location filename="../gui_qt/mainwindow.cpp" line="195"/>
<source>Unexpected error while saving file : %1</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../gui_qt/mainwindow.cpp" line="200"/>
<location filename="../gui_qt/mainwindow.cpp" line="202"/>
<source>Do you want to load a scenery from file ? Any unsaved changes will be lost.</source>
<translation>Voulez-vous charger une scène ? Les modifications non sauvegardées seront perdues.</translation>
</message>
<message>
<location filename="../gui_qt/mainwindow.cpp" line="200"/>
<location filename="../gui_qt/mainwindow.cpp" line="202"/>
<source>Paysages 3D - Load scenery</source>
<translation>Paysages 3D - Charger une scène</translation>
</message>
<message>
<location filename="../gui_qt/mainwindow.cpp" line="202"/>
<location filename="../gui_qt/mainwindow.cpp" line="204"/>
<source>Paysages 3D - Choose a scenery file to load</source>
<translation>Paysages 3D - Choisissez un fichier de scène à charger</translation>
</message>
<message>
<location filename="../gui_qt/mainwindow.cpp" line="212"/>
<location filename="../gui_qt/mainwindow.cpp" line="215"/>
<location filename="../gui_qt/mainwindow.cpp" line="218"/>
<location filename="../gui_qt/mainwindow.cpp" line="221"/>
<location filename="../gui_qt/mainwindow.cpp" line="214"/>
<location filename="../gui_qt/mainwindow.cpp" line="217"/>
<location filename="../gui_qt/mainwindow.cpp" line="220"/>
<location filename="../gui_qt/mainwindow.cpp" line="223"/>
<source>Paysages 3D - File loading error</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../gui_qt/mainwindow.cpp" line="212"/>
<location filename="../gui_qt/mainwindow.cpp" line="214"/>
<source>Can&apos;t read specified file : %1</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../gui_qt/mainwindow.cpp" line="215"/>
<location filename="../gui_qt/mainwindow.cpp" line="217"/>
<source>This file doesn&apos;t look like a Paysages 3D file : %1</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../gui_qt/mainwindow.cpp" line="218"/>
<location filename="../gui_qt/mainwindow.cpp" line="220"/>
<source>This file was created with an incompatible Paysages 3D version : %1</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../gui_qt/mainwindow.cpp" line="221"/>
<location filename="../gui_qt/mainwindow.cpp" line="223"/>
<source>Unexpected error while loading file : %1</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../gui_qt/mainwindow.cpp" line="229"/>
<location filename="../gui_qt/mainwindow.cpp" line="231"/>
<source>A 3D landscape editing and rendering software.
Authors :
@ -1197,7 +1202,7 @@ GLib - http://www.gtk.org/
<translation type="obsolete">Voulez-vous charger un paysage ? Les modifications nons sauvegardées seront perdues.</translation>
</message>
<message>
<location filename="../gui_qt/mainwindow.cpp" line="229"/>
<location filename="../gui_qt/mainwindow.cpp" line="231"/>
<source>Paysages 3D</source>
<translation>Paysages 3D</translation>
</message>