new element visibility button icons

loadfix
Marc Zinnschlag 10 years ago
parent 50a489321f
commit e04ead2bd5

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

@ -8,10 +8,10 @@ namespace CSVRender
{ {
// elements that are part of the actual scene // elements that are part of the actual scene
Element_Reference = 0x1, Element_Reference = 0x1,
Element_Terrain = 0x2, Element_Pathgrid = 0x2,
Element_Water = 0x4, Element_Water = 0x4,
Element_Pathgrid = 0x8, Element_Fog = 0x8,
Element_Fog = 0x10, Element_Terrain = 0x10,
// control elements // control elements
Element_CellMarker = 0x10000, Element_CellMarker = 0x10000,

@ -8,9 +8,13 @@
#include "worldspacewidget.hpp" #include "worldspacewidget.hpp"
#include "cell.hpp" #include "cell.hpp"
namespace CSVRender namespace CSVWidget
{ {
class SceneToolToggle;
}
namespace CSVRender
{
class TextOverlay; class TextOverlay;
class OverlayMask; class OverlayMask;

@ -15,6 +15,7 @@
#include "../../model/world/tablemimedata.hpp" #include "../../model/world/tablemimedata.hpp"
#include "../widget/scenetooltoggle.hpp" #include "../widget/scenetooltoggle.hpp"
#include "../widget/scenetooltoggle2.hpp"
#include "elements.hpp" #include "elements.hpp"
@ -33,11 +34,11 @@ void CSVRender::UnpagedWorldspaceWidget::update()
} }
void CSVRender::UnpagedWorldspaceWidget::addVisibilitySelectorButtons ( void CSVRender::UnpagedWorldspaceWidget::addVisibilitySelectorButtons (
CSVWidget::SceneToolToggle *tool) CSVWidget::SceneToolToggle2 *tool)
{ {
WorldspaceWidget::addVisibilitySelectorButtons (tool); WorldspaceWidget::addVisibilitySelectorButtons (tool);
tool->addButton (":armor.png", Element_Fog, ":armor.png", "Fog"); tool->addButton (Element_Fog, "Fog");
} }
CSVRender::UnpagedWorldspaceWidget::UnpagedWorldspaceWidget (const std::string& cellId, CSMDoc::Document& document, QWidget* parent) CSVRender::UnpagedWorldspaceWidget::UnpagedWorldspaceWidget (const std::string& cellId, CSMDoc::Document& document, QWidget* parent)

@ -34,7 +34,7 @@ namespace CSVRender
protected: protected:
virtual void addVisibilitySelectorButtons (CSVWidget::SceneToolToggle *tool); virtual void addVisibilitySelectorButtons (CSVWidget::SceneToolToggle2 *tool);
public: public:

@ -13,7 +13,7 @@
#include "../../model/world/idtable.hpp" #include "../../model/world/idtable.hpp"
#include "../widget/scenetoolmode.hpp" #include "../widget/scenetoolmode.hpp"
#include "../widget/scenetooltoggle.hpp" #include "../widget/scenetooltoggle2.hpp"
#include "../widget/scenetoolrun.hpp" #include "../widget/scenetoolrun.hpp"
#include "../world/physicsmanager.hpp" #include "../world/physicsmanager.hpp"
@ -127,10 +127,10 @@ CSVWidget::SceneToolMode *CSVRender::WorldspaceWidget::makeNavigationSelector (
return tool; return tool;
} }
CSVWidget::SceneToolToggle *CSVRender::WorldspaceWidget::makeSceneVisibilitySelector (CSVWidget::SceneToolbar *parent) CSVWidget::SceneToolToggle2 *CSVRender::WorldspaceWidget::makeSceneVisibilitySelector (CSVWidget::SceneToolbar *parent)
{ {
mSceneElements= new CSVWidget::SceneToolToggle (parent, mSceneElements = new CSVWidget::SceneToolToggle2 (parent,
"Scene Element Visibility", ":placeholder"); "Scene Element Visibility", ":scenetoolbar/scene-view-c", ":scenetoolbar/scene-view-");
addVisibilitySelectorButtons (mSceneElements); addVisibilitySelectorButtons (mSceneElements);
@ -260,12 +260,12 @@ unsigned int CSVRender::WorldspaceWidget::getInteractionMask() const
} }
void CSVRender::WorldspaceWidget::addVisibilitySelectorButtons ( void CSVRender::WorldspaceWidget::addVisibilitySelectorButtons (
CSVWidget::SceneToolToggle *tool) CSVWidget::SceneToolToggle2 *tool)
{ {
tool->addButton (":placeholder", Element_Reference, ":placeholder", "References"); tool->addButton (Element_Reference, "References");
tool->addButton (":placeholder", Element_Terrain, ":placeholder", "Terrain"); tool->addButton (Element_Terrain, "Terrain");
tool->addButton (":placeholder", Element_Water, ":placeholder", "Water"); tool->addButton (Element_Water, "Water");
tool->addButton (":placeholder", Element_Pathgrid, ":placeholder", "Pathgrid"); tool->addButton (Element_Pathgrid, "Pathgrid");
} }
void CSVRender::WorldspaceWidget::addEditModeSelectorButtons (CSVWidget::SceneToolMode *tool) void CSVRender::WorldspaceWidget::addEditModeSelectorButtons (CSVWidget::SceneToolMode *tool)

@ -18,7 +18,7 @@ namespace CSMWorld
namespace CSVWidget namespace CSVWidget
{ {
class SceneToolMode; class SceneToolMode;
class SceneToolToggle; class SceneToolToggle2;
class SceneToolbar; class SceneToolbar;
class SceneToolRun; class SceneToolRun;
} }
@ -37,7 +37,7 @@ namespace CSVRender
CSVRender::Navigation1st m1st; CSVRender::Navigation1st m1st;
CSVRender::NavigationFree mFree; CSVRender::NavigationFree mFree;
CSVRender::NavigationOrbit mOrbit; CSVRender::NavigationOrbit mOrbit;
CSVWidget::SceneToolToggle *mSceneElements; CSVWidget::SceneToolToggle2 *mSceneElements;
CSVWidget::SceneToolRun *mRun; CSVWidget::SceneToolRun *mRun;
CSMDoc::Document& mDocument; CSMDoc::Document& mDocument;
CSVWorld::PhysicsSystem *mPhysics; CSVWorld::PhysicsSystem *mPhysics;
@ -71,7 +71,7 @@ namespace CSVRender
/// \attention The created tool is not added to the toolbar (via addTool). Doing /// \attention The created tool is not added to the toolbar (via addTool). Doing
/// that is the responsibility of the calling function. /// that is the responsibility of the calling function.
CSVWidget::SceneToolToggle *makeSceneVisibilitySelector ( CSVWidget::SceneToolToggle2 *makeSceneVisibilitySelector (
CSVWidget::SceneToolbar *parent); CSVWidget::SceneToolbar *parent);
/// \attention The created tool is not added to the toolbar (via addTool). Doing /// \attention The created tool is not added to the toolbar (via addTool). Doing
@ -107,7 +107,7 @@ namespace CSVRender
protected: protected:
virtual void addVisibilitySelectorButtons (CSVWidget::SceneToolToggle *tool); virtual void addVisibilitySelectorButtons (CSVWidget::SceneToolToggle2 *tool);
virtual void addEditModeSelectorButtons (CSVWidget::SceneToolMode *tool); virtual void addEditModeSelectorButtons (CSVWidget::SceneToolMode *tool);

@ -0,0 +1,139 @@
#include "scenetooltoggle2.hpp"
#include <stdexcept>
#include <sstream>
#include <QHBoxLayout>
#include <QFrame>
#include <QIcon>
#include <QPainter>
#include "scenetoolbar.hpp"
#include "pushbutton.hpp"
void CSVWidget::SceneToolToggle2::adjustToolTip()
{
QString toolTip = mToolTip;
toolTip += "<p>Currently enabled: ";
bool first = true;
for (std::map<PushButton *, ButtonDesc>::const_iterator iter (mButtons.begin());
iter!=mButtons.end(); ++iter)
if (iter->first->isChecked())
{
if (!first)
toolTip += ", ";
else
first = false;
toolTip += iter->second.mName;
}
if (first)
toolTip += "none";
toolTip += "<p>(left click to alter selection)";
setToolTip (toolTip);
}
void CSVWidget::SceneToolToggle2::adjustIcon()
{
std::ostringstream stream;
stream << mCompositeIcon << getSelection();
setIcon (QIcon (QString::fromUtf8 (stream.str().c_str())));
}
CSVWidget::SceneToolToggle2::SceneToolToggle2 (SceneToolbar *parent, const QString& toolTip,
const std::string& compositeIcon, const std::string& singleIcon)
: SceneTool (parent), mCompositeIcon (compositeIcon), mSingleIcon (singleIcon),
mButtonSize (parent->getButtonSize()), mIconSize (parent->getIconSize()), mToolTip (toolTip),
mFirst (0)
{
mPanel = new QFrame (this, Qt::Popup);
mLayout = new QHBoxLayout (mPanel);
mLayout->setContentsMargins (QMargins (0, 0, 0, 0));
mPanel->setLayout (mLayout);
}
void CSVWidget::SceneToolToggle2::showPanel (const QPoint& position)
{
mPanel->move (position);
mPanel->show();
if (mFirst)
mFirst->setFocus (Qt::OtherFocusReason);
}
void CSVWidget::SceneToolToggle2::addButton (unsigned int id,
const QString& name, const QString& tooltip)
{
std::ostringstream stream;
stream << mSingleIcon << id;
PushButton *button = new PushButton (QIcon (QPixmap (stream.str().c_str())),
PushButton::Type_Toggle, tooltip.isEmpty() ? name: tooltip, mPanel);
button->setSizePolicy (QSizePolicy (QSizePolicy::Fixed, QSizePolicy::Fixed));
button->setIconSize (QSize (mIconSize, mIconSize));
button->setFixedSize (mButtonSize, mButtonSize);
mLayout->addWidget (button);
ButtonDesc desc;
desc.mId = id;
desc.mName = name;
desc.mIndex = mButtons.size();
mButtons.insert (std::make_pair (button, desc));
connect (button, SIGNAL (clicked()), this, SLOT (selected()));
if (mButtons.size()==1)
mFirst = button;
}
unsigned int CSVWidget::SceneToolToggle2::getSelection() const
{
unsigned int selection = 0;
for (std::map<PushButton *, ButtonDesc>::const_iterator iter (mButtons.begin());
iter!=mButtons.end(); ++iter)
if (iter->first->isChecked())
selection |= iter->second.mId;
return selection;
}
void CSVWidget::SceneToolToggle2::setSelection (unsigned int selection)
{
for (std::map<PushButton *, ButtonDesc>::iterator iter (mButtons.begin());
iter!=mButtons.end(); ++iter)
iter->first->setChecked (selection & iter->second.mId);
adjustToolTip();
adjustIcon();
}
void CSVWidget::SceneToolToggle2::selected()
{
std::map<PushButton *, ButtonDesc>::const_iterator iter =
mButtons.find (dynamic_cast<PushButton *> (sender()));
if (iter!=mButtons.end())
{
if (!iter->first->hasKeepOpen())
mPanel->hide();
adjustToolTip();
adjustIcon();
emit selectionChanged();
}
}

@ -0,0 +1,76 @@
#ifndef CSV_WIDGET_SCENETOOL_TOGGLE2_H
#define CSV_WIDGET_SCENETOOL_TOGGLE2_H
#include "scenetool.hpp"
#include <map>
class QHBoxLayout;
class QRect;
namespace CSVWidget
{
class SceneToolbar;
class PushButton;
///< \brief Multi-Toggle tool
///
/// Top level button is using predefined icons instead building a composite icon.
class SceneToolToggle2 : public SceneTool
{
Q_OBJECT
struct ButtonDesc
{
unsigned int mId;
QString mName;
int mIndex;
};
std::string mCompositeIcon;
std::string mSingleIcon;
QWidget *mPanel;
QHBoxLayout *mLayout;
std::map<PushButton *, ButtonDesc> mButtons; // widget, id
int mButtonSize;
int mIconSize;
QString mToolTip;
PushButton *mFirst;
void adjustToolTip();
void adjustIcon();
public:
/// The top level icon is compositeIcon + sum of bitpatterns for active buttons (in
/// decimal)
///
/// The icon for individual toggle buttons is signleIcon + bitmask for button (in
/// decimal)
SceneToolToggle2 (SceneToolbar *parent, const QString& toolTip,
const std::string& compositeIcon, const std::string& singleIcon);
virtual void showPanel (const QPoint& position);
/// \attention After the last button has been added, setSelection must be called at
/// least once to finalise the layout.
void addButton (unsigned int id,
const QString& name, const QString& tooltip = "");
unsigned int getSelection() const;
/// \param or'ed button IDs. IDs that do not exist will be ignored.
void setSelection (unsigned int selection);
signals:
void selectionChanged();
private slots:
void selected();
};
}
#endif

@ -20,6 +20,7 @@
#include "../widget/scenetoolbar.hpp" #include "../widget/scenetoolbar.hpp"
#include "../widget/scenetoolmode.hpp" #include "../widget/scenetoolmode.hpp"
#include "../widget/scenetooltoggle.hpp" #include "../widget/scenetooltoggle.hpp"
#include "../widget/scenetooltoggle2.hpp"
#include "../widget/scenetoolrun.hpp" #include "../widget/scenetoolrun.hpp"
#include "tablebottombox.hpp" #include "tablebottombox.hpp"
@ -109,7 +110,7 @@ CSVWidget::SceneToolbar* CSVWorld::SceneSubView::makeToolbar (CSVRender::Worldsp
CSVWidget::SceneToolMode *lightingTool = widget->makeLightingSelector (toolbar); CSVWidget::SceneToolMode *lightingTool = widget->makeLightingSelector (toolbar);
toolbar->addTool (lightingTool); toolbar->addTool (lightingTool);
CSVWidget::SceneToolToggle *sceneVisibilityTool = CSVWidget::SceneToolToggle2 *sceneVisibilityTool =
widget->makeSceneVisibilitySelector (toolbar); widget->makeSceneVisibilitySelector (toolbar);
toolbar->addTool (sceneVisibilityTool); toolbar->addTool (sceneVisibilityTool);

@ -80,5 +80,42 @@
<file alias="free-camera">flying eye.png</file> <file alias="free-camera">flying eye.png</file>
<file alias="orbiting-camera">orbit2.png</file> <file alias="orbiting-camera">orbit2.png</file>
<file alias="play">scene-play.png</file> <file alias="play">scene-play.png</file>
<file alias="scene-view-1">scene-view-references.png</file>
<file alias="scene-view-16">scene-view-terrain.png</file>
<file alias="scene-view-4">scene-view-water.png</file>
<file alias="scene-view-2">scene-view-pathgrid.png</file>
<file alias="scene-view-8">scene-view-fog.png</file>
<file alias="scene-view-c0">scene-view-status-0.png</file>
<file alias="scene-view-c1">scene-view-status-1.png</file>
<file alias="scene-view-c2">scene-view-status-2.png</file>
<file alias="scene-view-c3">scene-view-status-3.png</file>
<file alias="scene-view-c4">scene-view-status-4.png</file>
<file alias="scene-view-c5">scene-view-status-5.png</file>
<file alias="scene-view-c6">scene-view-status-6.png</file>
<file alias="scene-view-c7">scene-view-status-7.png</file>
<file alias="scene-view-c8">scene-view-status-8.png</file>
<file alias="scene-view-c9">scene-view-status-9.png</file>
<file alias="scene-view-c10">scene-view-status-10.png</file>
<file alias="scene-view-c11">scene-view-status-11.png</file>
<file alias="scene-view-c12">scene-view-status-12.png</file>
<file alias="scene-view-c13">scene-view-status-13.png</file>
<file alias="scene-view-c14">scene-view-status-14.png</file>
<file alias="scene-view-c15">scene-view-status-15.png</file>
<file alias="scene-view-c16">scene-view-status-16.png</file>
<file alias="scene-view-c17">scene-view-status-17.png</file>
<file alias="scene-view-c18">scene-view-status-18.png</file>
<file alias="scene-view-c19">scene-view-status-19.png</file>
<file alias="scene-view-c20">scene-view-status-20.png</file>
<file alias="scene-view-c21">scene-view-status-21.png</file>
<file alias="scene-view-c22">scene-view-status-22.png</file>
<file alias="scene-view-c23">scene-view-status-23.png</file>
<file alias="scene-view-c24">scene-view-status-24.png</file>
<file alias="scene-view-c25">scene-view-status-25.png</file>
<file alias="scene-view-c26">scene-view-status-26.png</file>
<file alias="scene-view-c27">scene-view-status-27.png</file>
<file alias="scene-view-c28">scene-view-status-28.png</file>
<file alias="scene-view-c29">scene-view-status-29.png</file>
<file alias="scene-view-c30">scene-view-status-30.png</file>
<file alias="scene-view-c31">scene-view-status-31.png</file>
</qresource> </qresource>
</RCC> </RCC>

Loading…
Cancel
Save