mirror of
https://github.com/OpenMW/openmw.git
synced 2025-02-21 10:39:41 +00:00
added self-adjusting tooltips to the top-level toolbar buttons
This commit is contained in:
parent
26f87f5d23
commit
c2ea8f3f0a
6 changed files with 44 additions and 18 deletions
|
@ -56,7 +56,7 @@ namespace CSVRender
|
|||
|
||||
CSVWidget::SceneToolMode *SceneWidget::makeLightingSelector (CSVWidget::SceneToolbar *parent)
|
||||
{
|
||||
CSVWidget::SceneToolMode *tool = new CSVWidget::SceneToolMode (parent);
|
||||
CSVWidget::SceneToolMode *tool = new CSVWidget::SceneToolMode (parent, "Lighting Mode");
|
||||
|
||||
/// \todo replace icons
|
||||
tool->addButton (":door.png", "day",
|
||||
|
|
|
@ -57,7 +57,7 @@ void CSVRender::WorldspaceWidget::selectDefaultNavigationMode()
|
|||
CSVWidget::SceneToolMode *CSVRender::WorldspaceWidget::makeNavigationSelector (
|
||||
CSVWidget::SceneToolbar *parent)
|
||||
{
|
||||
CSVWidget::SceneToolMode *tool = new CSVWidget::SceneToolMode (parent);
|
||||
CSVWidget::SceneToolMode *tool = new CSVWidget::SceneToolMode (parent, "Camera Mode");
|
||||
|
||||
/// \todo replace icons
|
||||
/// \todo consider user-defined button-mapping
|
||||
|
|
|
@ -4,11 +4,11 @@
|
|||
#include <QMouseEvent>
|
||||
#include <QKeyEvent>
|
||||
|
||||
void CSVWidget::PushButton::setExtendedToolTip (const std::string& text)
|
||||
void CSVWidget::PushButton::setExtendedToolTip (const QString& text)
|
||||
{
|
||||
std::string tooltip = text;
|
||||
QString tooltip = text;
|
||||
|
||||
if (tooltip.empty())
|
||||
if (tooltip.isEmpty())
|
||||
tooltip = "(Tool tip not implemented yet)";
|
||||
|
||||
switch (mType)
|
||||
|
@ -29,7 +29,7 @@ void CSVWidget::PushButton::setExtendedToolTip (const std::string& text)
|
|||
break;
|
||||
}
|
||||
|
||||
setToolTip (QString::fromUtf8 (tooltip.c_str()));
|
||||
setToolTip (tooltip);
|
||||
}
|
||||
|
||||
void CSVWidget::PushButton::keyPressEvent (QKeyEvent *event)
|
||||
|
@ -57,16 +57,16 @@ void CSVWidget::PushButton::mouseReleaseEvent (QMouseEvent *event)
|
|||
QPushButton::mouseReleaseEvent (event);
|
||||
}
|
||||
|
||||
CSVWidget::PushButton::PushButton (const QIcon& icon, Type type, const std::string& tooltip,
|
||||
CSVWidget::PushButton::PushButton (const QIcon& icon, Type type, const QString& tooltip,
|
||||
QWidget *parent)
|
||||
: QPushButton (icon, "", parent), mKeepOpen (false), mType (type)
|
||||
: QPushButton (icon, "", parent), mKeepOpen (false), mType (type), mToolTip (tooltip)
|
||||
{
|
||||
setCheckable (type==Type_Mode);
|
||||
setExtendedToolTip (tooltip);
|
||||
}
|
||||
|
||||
CSVWidget::PushButton::PushButton (Type type, const std::string& tooltip, QWidget *parent)
|
||||
: QPushButton (parent), mKeepOpen (false), mType (type)
|
||||
CSVWidget::PushButton::PushButton (Type type, const QString& tooltip, QWidget *parent)
|
||||
: QPushButton (parent), mKeepOpen (false), mType (type), mToolTip (tooltip)
|
||||
{
|
||||
setCheckable (type==Type_Mode);
|
||||
setExtendedToolTip (tooltip);
|
||||
|
@ -75,4 +75,9 @@ CSVWidget::PushButton::PushButton (Type type, const std::string& tooltip, QWidge
|
|||
bool CSVWidget::PushButton::hasKeepOpen() const
|
||||
{
|
||||
return mKeepOpen;
|
||||
}
|
||||
|
||||
QString CSVWidget::PushButton::getBaseToolTip() const
|
||||
{
|
||||
return mToolTip;
|
||||
}
|
|
@ -21,10 +21,11 @@ namespace CSVWidget
|
|||
|
||||
bool mKeepOpen;
|
||||
Type mType;
|
||||
QString mToolTip;
|
||||
|
||||
private:
|
||||
|
||||
void setExtendedToolTip (const std::string& text);
|
||||
void setExtendedToolTip (const QString& text);
|
||||
|
||||
protected:
|
||||
|
||||
|
@ -37,14 +38,17 @@ namespace CSVWidget
|
|||
public:
|
||||
|
||||
/// \param push Do not maintain a toggle state
|
||||
PushButton (const QIcon& icon, Type type, const std::string& tooltip = "",
|
||||
PushButton (const QIcon& icon, Type type, const QString& tooltip = "",
|
||||
QWidget *parent = 0);
|
||||
|
||||
/// \param push Do not maintain a toggle state
|
||||
PushButton (Type type, const std::string& tooltip = "",
|
||||
PushButton (Type type, const QString& tooltip = "",
|
||||
QWidget *parent = 0);
|
||||
|
||||
bool hasKeepOpen() const;
|
||||
|
||||
/// Return tooltip used at construction (without any button-specific modifications)
|
||||
QString getBaseToolTip() const;
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -8,8 +8,20 @@
|
|||
#include "scenetoolbar.hpp"
|
||||
#include "pushbutton.hpp"
|
||||
|
||||
CSVWidget::SceneToolMode::SceneToolMode (SceneToolbar *parent)
|
||||
: SceneTool (parent), mButtonSize (parent->getButtonSize()), mIconSize (parent->getIconSize())
|
||||
void CSVWidget::SceneToolMode::adjustToolTip (const PushButton *activeMode)
|
||||
{
|
||||
QString toolTip = mToolTip;
|
||||
|
||||
toolTip += "<p>Currently selected: " + activeMode->getBaseToolTip();
|
||||
|
||||
toolTip += "<p>(left click to change mode)";
|
||||
|
||||
setToolTip (toolTip);
|
||||
}
|
||||
|
||||
CSVWidget::SceneToolMode::SceneToolMode (SceneToolbar *parent, const QString& toolTip)
|
||||
: SceneTool (parent), mButtonSize (parent->getButtonSize()), mIconSize (parent->getIconSize()),
|
||||
mToolTip (toolTip)
|
||||
{
|
||||
mPanel = new QFrame (this, Qt::Popup);
|
||||
|
||||
|
@ -30,7 +42,7 @@ void CSVWidget::SceneToolMode::showPanel (const QPoint& position)
|
|||
}
|
||||
|
||||
void CSVWidget::SceneToolMode::addButton (const std::string& icon, const std::string& id,
|
||||
const std::string& tooltip)
|
||||
const QString& tooltip)
|
||||
{
|
||||
PushButton *button = new PushButton (QIcon (QPixmap (icon.c_str())), PushButton::Type_Mode,
|
||||
tooltip, mPanel);
|
||||
|
@ -48,6 +60,7 @@ void CSVWidget::SceneToolMode::addButton (const std::string& icon, const std::st
|
|||
{
|
||||
setIcon (button->icon());
|
||||
button->setChecked (true);
|
||||
adjustToolTip (button);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -66,6 +79,7 @@ void CSVWidget::SceneToolMode::selected()
|
|||
iter2->first->setChecked (iter2==iter);
|
||||
|
||||
setIcon (iter->first->icon());
|
||||
adjustToolTip (iter->first);
|
||||
emit modeChanged (iter->second);
|
||||
}
|
||||
}
|
|
@ -22,15 +22,18 @@ namespace CSVWidget
|
|||
std::map<PushButton *, std::string> mButtons; // widget, id
|
||||
int mButtonSize;
|
||||
int mIconSize;
|
||||
QString mToolTip;
|
||||
|
||||
void adjustToolTip (const PushButton *activeMode);
|
||||
|
||||
public:
|
||||
|
||||
SceneToolMode (SceneToolbar *parent);
|
||||
SceneToolMode (SceneToolbar *parent, const QString& toolTip);
|
||||
|
||||
virtual void showPanel (const QPoint& position);
|
||||
|
||||
void addButton (const std::string& icon, const std::string& id,
|
||||
const std::string& tooltip = "");
|
||||
const QString& tooltip = "");
|
||||
|
||||
signals:
|
||||
|
||||
|
|
Loading…
Reference in a new issue