implemented SceneToolMode as a horizontal panel with radiobutton-type buttons

pull/37/head
Marc Zinnschlag 11 years ago
parent 0c5f07a65a
commit 7be1f1afc2

@ -30,7 +30,12 @@ CSVWorld::SceneSubView::SceneSubView (const CSMWorld::UniversalId& id, CSMDoc::D
layout2->setContentsMargins (QMargins (0, 0, 0, 0));
SceneToolbar *toolbar = new SceneToolbar (this);
toolbar->addTool (new SceneToolMode (this)); // test
// test
SceneToolMode *tool = new SceneToolMode (this);
tool->addButton (":door.png", "a");
tool->addButton (":GMST.png", "b");
tool->addButton (":Info.png", "c");
toolbar->addTool (tool);
toolbar->addTool (new SceneToolMode (this));
toolbar->addTool (new SceneToolMode (this));
toolbar->addTool (new SceneToolMode (this));

@ -5,4 +5,16 @@ CSVWorld::SceneTool::SceneTool (QWidget *parent) : QPushButton (parent)
{
setSizePolicy (QSizePolicy (QSizePolicy::Fixed, QSizePolicy::Fixed));
setFixedSize (48, 48);
}
connect (this, SIGNAL (clicked()), this, SLOT (openRequest()));
}
void CSVWorld::SceneTool::updateIcon (const QIcon& icon)
{
setIcon (icon);
}
void CSVWorld::SceneTool::openRequest()
{
showPanel (parentWidget()->mapToGlobal (pos()));
}

@ -14,6 +14,15 @@ namespace CSVWorld
SceneTool (QWidget *parent = 0);
virtual void showPanel (const QPoint& position) = 0;
protected slots:
void updateIcon (const QIcon& icon);
private slots:
void openRequest();
};
}

@ -1,6 +1,51 @@
#include "scenetoolmode.hpp"
#include <QHBoxLayout>
#include <QFrame>
#include <QSignalMapper>
CSVWorld::SceneToolMode::SceneToolMode (QWidget *parent)
: SceneTool (parent)
{}
{
mPanel = new QFrame (this, Qt::Popup);
mLayout = new QHBoxLayout (mPanel);
mLayout->setContentsMargins (QMargins (0, 0, 0, 0));
mPanel->setLayout (mLayout);
}
void CSVWorld::SceneToolMode::showPanel (const QPoint& position)
{
mPanel->move (position);
mPanel->show();
}
void CSVWorld::SceneToolMode::addButton (const std::string& icon, const std::string& id)
{
QPushButton *button = new QPushButton (QIcon (QPixmap (icon.c_str())), "", mPanel);
button->setSizePolicy (QSizePolicy (QSizePolicy::Fixed, QSizePolicy::Fixed));
button->setFixedSize (48, 48);
mLayout->addWidget (button);
mButtons.insert (std::make_pair (button, id));
connect (button, SIGNAL (clicked()), this, SLOT (selected()));
}
void CSVWorld::SceneToolMode::selected()
{
std::map<QPushButton *, std::string>::const_iterator iter =
mButtons.find (dynamic_cast<QPushButton *> (sender()));
if (iter!=mButtons.end())
{
mPanel->hide();
emit updateIcon (iter->first->icon());
emit modeChanged (iter->second);
}
}

@ -3,6 +3,10 @@
#include "scenetool.hpp"
#include <map>
class QHBoxLayout;
namespace CSVWorld
{
///< \brief Mode selector tool
@ -10,9 +14,25 @@ namespace CSVWorld
{
Q_OBJECT
QWidget *mPanel;
QHBoxLayout *mLayout;
std::map<QPushButton *, std::string> mButtons; // widget, id
public:
SceneToolMode (QWidget *parent = 0);
virtual void showPanel (const QPoint& position);
void addButton (const std::string& icon, const std::string& id);
signals:
void modeChanged (const std::string& id);
private slots:
void selected();
};
}

Loading…
Cancel
Save