added ModeButton specialisation of PushButton for use in SceneToolMode

loadfix
Marc Zinnschlag 10 years ago
parent bf40a3bb5d
commit 4dd645559d

@ -72,7 +72,7 @@ opencs_units_noqt (view/world
)
opencs_units (view/widget
scenetoolbar scenetool scenetoolmode pushbutton scenetooltoggle scenetoolrun
scenetoolbar scenetool scenetoolmode pushbutton scenetooltoggle scenetoolrun modebutton
)
opencs_units (view/render

@ -0,0 +1,10 @@
#include "modebutton.hpp"
CSVWidget::ModeButton::ModeButton (const QIcon& icon, const QString& tooltip, QWidget *parent)
: PushButton (icon, Type_Mode, tooltip, parent)
{}
void CSVWidget::ModeButton::activate (SceneToolbar *toolbar) {}
void CSVWidget::ModeButton::deactivate (SceneToolbar *toolbar) {}

@ -0,0 +1,28 @@
#ifndef CSV_WIDGET_MODEBUTTON_H
#define CSV_WIDGET_MODEBUTTON_H
#include "pushbutton.hpp"
namespace CSVWidget
{
class SceneToolbar;
/// \brief Specialist PushButton of Type_Mode for use in SceneToolMode
class ModeButton : public PushButton
{
Q_OBJECT
public:
ModeButton (const QIcon& icon, const QString& tooltip = "",
QWidget *parent = 0);
/// Default-Implementation: do nothing
virtual void activate (SceneToolbar *toolbar);
/// Default-Implementation: do nothing
virtual void deactivate (SceneToolbar *toolbar);
};
}
#endif

@ -6,9 +6,9 @@
#include <QSignalMapper>
#include "scenetoolbar.hpp"
#include "pushbutton.hpp"
#include "modebutton.hpp"
void CSVWidget::SceneToolMode::adjustToolTip (const PushButton *activeMode)
void CSVWidget::SceneToolMode::adjustToolTip (const ModeButton *activeMode)
{
QString toolTip = mToolTip;
@ -21,7 +21,7 @@ void CSVWidget::SceneToolMode::adjustToolTip (const PushButton *activeMode)
CSVWidget::SceneToolMode::SceneToolMode (SceneToolbar *parent, const QString& toolTip)
: SceneTool (parent), mButtonSize (parent->getButtonSize()), mIconSize (parent->getIconSize()),
mToolTip (toolTip), mFirst (0)
mToolTip (toolTip), mFirst (0), mCurrent (0), mToolbar (parent)
{
mPanel = new QFrame (this, Qt::Popup);
@ -44,8 +44,7 @@ void CSVWidget::SceneToolMode::showPanel (const QPoint& position)
void CSVWidget::SceneToolMode::addButton (const std::string& icon, const std::string& id,
const QString& tooltip)
{
PushButton *button = new PushButton (QIcon (QPixmap (icon.c_str())), PushButton::Type_Mode,
tooltip, mPanel);
ModeButton *button = new ModeButton (QIcon (QPixmap (icon.c_str())), tooltip, mPanel);
button->setSizePolicy (QSizePolicy (QSizePolicy::Fixed, QSizePolicy::Fixed));
button->setIconSize (QSize (mIconSize, mIconSize));
button->setFixedSize (mButtonSize, mButtonSize);
@ -58,29 +57,40 @@ void CSVWidget::SceneToolMode::addButton (const std::string& icon, const std::st
if (mButtons.size()==1)
{
mFirst = button;
mFirst = mCurrent = button;
setIcon (button->icon());
button->setChecked (true);
adjustToolTip (button);
mCurrent->activate (mToolbar);
}
}
void CSVWidget::SceneToolMode::selected()
{
std::map<PushButton *, std::string>::const_iterator iter =
mButtons.find (dynamic_cast<PushButton *> (sender()));
std::map<ModeButton *, std::string>::const_iterator iter =
mButtons.find (dynamic_cast<ModeButton *> (sender()));
if (iter!=mButtons.end())
{
if (!iter->first->hasKeepOpen())
mPanel->hide();
for (std::map<PushButton *, std::string>::const_iterator iter2 = mButtons.begin();
for (std::map<ModeButton *, std::string>::const_iterator iter2 = mButtons.begin();
iter2!=mButtons.end(); ++iter2)
iter2->first->setChecked (iter2==iter);
setIcon (iter->first->icon());
adjustToolTip (iter->first);
if (mCurrent!=iter->first)
{
if (mCurrent)
mCurrent->deactivate (mToolbar);
mCurrent = iter->first;
mCurrent->activate (mToolbar);
}
emit modeChanged (iter->second);
}
}

@ -10,7 +10,7 @@ class QHBoxLayout;
namespace CSVWidget
{
class SceneToolbar;
class PushButton;
class ModeButton;
///< \brief Mode selector tool
class SceneToolMode : public SceneTool
@ -19,13 +19,15 @@ namespace CSVWidget
QWidget *mPanel;
QHBoxLayout *mLayout;
std::map<PushButton *, std::string> mButtons; // widget, id
std::map<ModeButton *, std::string> mButtons; // widget, id
int mButtonSize;
int mIconSize;
QString mToolTip;
PushButton *mFirst;
ModeButton *mCurrent;
SceneToolbar *mToolbar;
void adjustToolTip (const PushButton *activeMode);
void adjustToolTip (const ModeButton *activeMode);
public:

Loading…
Cancel
Save