added profile selection panel

This commit is contained in:
Marc Zinnschlag 2014-09-07 14:40:50 +02:00
parent 4337d05126
commit 3f24593dba
2 changed files with 76 additions and 0 deletions

View file

@ -1,6 +1,12 @@
#include "scenetoolrun.hpp" #include "scenetoolrun.hpp"
#include <QFrame>
#include <QTableWidget>
#include <QHBoxLayout>
#include <QHeaderView>
#include <QApplication>
void CSVWidget::SceneToolRun::adjustToolTips() void CSVWidget::SceneToolRun::adjustToolTips()
{ {
QString toolTip = mToolTip; QString toolTip = mToolTip;
@ -8,7 +14,10 @@ void CSVWidget::SceneToolRun::adjustToolTips()
if (mCurrentIndex==-1) if (mCurrentIndex==-1)
toolTip += "<p>No debug profile selected (function disabled)"; toolTip += "<p>No debug profile selected (function disabled)";
else else
{
toolTip += "<p>Debug profile: " + QString::fromUtf8 (mProfiles[mCurrentIndex].c_str()); toolTip += "<p>Debug profile: " + QString::fromUtf8 (mProfiles[mCurrentIndex].c_str());
toolTip += "<p>(right click to switch to a different profile)";
}
setToolTip (toolTip); setToolTip (toolTip);
} }
@ -18,6 +27,19 @@ void CSVWidget::SceneToolRun::updateIcon()
setIcon (QIcon (mCurrentIndex==-1 ? mIconDisabled : mIcon)); setIcon (QIcon (mCurrentIndex==-1 ? mIconDisabled : mIcon));
} }
void CSVWidget::SceneToolRun::updatePanel()
{
mTable->setRowCount (mProfiles.size());
for (int i=0; i<static_cast<int> (mProfiles.size()); ++i)
{
mTable->setItem (i, 0, new QTableWidgetItem (QString::fromUtf8 (mProfiles[i].c_str())));
mTable->setItem (i, 1, new QTableWidgetItem (
QApplication::style()->standardIcon (QStyle::SP_TitleBarCloseButton), ""));
}
}
CSVWidget::SceneToolRun::SceneToolRun (SceneToolbar *parent, const QString& toolTip, CSVWidget::SceneToolRun::SceneToolRun (SceneToolbar *parent, const QString& toolTip,
const QString& icon, const QString& iconDisabled, const std::vector<std::string>& profiles) const QString& icon, const QString& iconDisabled, const std::vector<std::string>& profiles)
: SceneTool (parent, Type_TopAction), mProfiles (profiles), : SceneTool (parent, Type_TopAction), mProfiles (profiles),
@ -26,11 +48,34 @@ CSVWidget::SceneToolRun::SceneToolRun (SceneToolbar *parent, const QString& tool
{ {
updateIcon(); updateIcon();
adjustToolTips(); adjustToolTips();
mPanel = new QFrame (this, Qt::Popup);
QHBoxLayout *layout = new QHBoxLayout (mPanel);
layout->setContentsMargins (QMargins (0, 0, 0, 0));
mTable = new QTableWidget (0, 2, this);
mTable->setShowGrid (false);
mTable->verticalHeader()->hide();
mTable->horizontalHeader()->hide();
mTable->horizontalHeader()->setResizeMode (0, QHeaderView::Stretch);
mTable->horizontalHeader()->setResizeMode (1, QHeaderView::ResizeToContents);
mTable->setSelectionMode (QAbstractItemView::NoSelection);
layout->addWidget (mTable);
connect (mTable, SIGNAL (clicked (const QModelIndex&)),
this, SLOT (clicked (const QModelIndex&)));
} }
void CSVWidget::SceneToolRun::showPanel (const QPoint& position) void CSVWidget::SceneToolRun::showPanel (const QPoint& position)
{ {
updatePanel();
mPanel->move (position);
mPanel->show();
} }
void CSVWidget::SceneToolRun::activate() void CSVWidget::SceneToolRun::activate()
@ -57,3 +102,20 @@ void CSVWidget::SceneToolRun::removeProfile (const std::string& profile)
adjustToolTips(); adjustToolTips();
} }
} }
void CSVWidget::SceneToolRun::clicked (const QModelIndex& index)
{
if (index.column()==0)
{
// select profile
mCurrentIndex = index.row();
mPanel->hide();
adjustToolTips();
}
else if (index.column()==1)
{
// remove profile from list
removeProfile (mProfiles.at (index.row()));
updatePanel();
}
}

View file

@ -6,6 +6,10 @@
#include "scenetool.hpp" #include "scenetool.hpp"
class QFrame;
class QTableWidget;
class QModelIndex;
namespace CSVWidget namespace CSVWidget
{ {
class SceneToolRun : public SceneTool class SceneToolRun : public SceneTool
@ -17,6 +21,8 @@ namespace CSVWidget
QString mToolTip; QString mToolTip;
QString mIcon; QString mIcon;
QString mIconDisabled; QString mIconDisabled;
QFrame *mPanel;
QTableWidget *mTable;
private: private:
@ -24,6 +30,8 @@ namespace CSVWidget
void updateIcon(); void updateIcon();
void updatePanel();
public: public:
SceneToolRun (SceneToolbar *parent, const QString& toolTip, const QString& icon, SceneToolRun (SceneToolbar *parent, const QString& toolTip, const QString& icon,
@ -33,8 +41,14 @@ namespace CSVWidget
virtual void activate(); virtual void activate();
/// \attention This function does not remove the profile from the profile selection
/// panel.
void removeProfile (const std::string& profile); void removeProfile (const std::string& profile);
private slots:
void clicked (const QModelIndex& index);
signals: signals:
void runRequest (const std::string& profile); void runRequest (const std::string& profile);