diff --git a/apps/opencs/view/widget/scenetoolrun.cpp b/apps/opencs/view/widget/scenetoolrun.cpp index 4a89c9fe9..f378725ae 100644 --- a/apps/opencs/view/widget/scenetoolrun.cpp +++ b/apps/opencs/view/widget/scenetoolrun.cpp @@ -1,6 +1,12 @@ #include "scenetoolrun.hpp" +#include +#include +#include +#include +#include + void CSVWidget::SceneToolRun::adjustToolTips() { QString toolTip = mToolTip; @@ -8,7 +14,10 @@ void CSVWidget::SceneToolRun::adjustToolTips() if (mCurrentIndex==-1) toolTip += "

No debug profile selected (function disabled)"; else + { toolTip += "

Debug profile: " + QString::fromUtf8 (mProfiles[mCurrentIndex].c_str()); + toolTip += "

(right click to switch to a different profile)"; + } setToolTip (toolTip); } @@ -18,6 +27,19 @@ void CSVWidget::SceneToolRun::updateIcon() setIcon (QIcon (mCurrentIndex==-1 ? mIconDisabled : mIcon)); } +void CSVWidget::SceneToolRun::updatePanel() +{ + mTable->setRowCount (mProfiles.size()); + + for (int i=0; i (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, const QString& icon, const QString& iconDisabled, const std::vector& profiles) : SceneTool (parent, Type_TopAction), mProfiles (profiles), @@ -26,11 +48,34 @@ CSVWidget::SceneToolRun::SceneToolRun (SceneToolbar *parent, const QString& tool { updateIcon(); 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) { + updatePanel(); + mPanel->move (position); + mPanel->show(); } void CSVWidget::SceneToolRun::activate() @@ -56,4 +101,21 @@ void CSVWidget::SceneToolRun::removeProfile (const std::string& profile) 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(); + } } \ No newline at end of file diff --git a/apps/opencs/view/widget/scenetoolrun.hpp b/apps/opencs/view/widget/scenetoolrun.hpp index b1ea3229d..609ddcd34 100644 --- a/apps/opencs/view/widget/scenetoolrun.hpp +++ b/apps/opencs/view/widget/scenetoolrun.hpp @@ -6,6 +6,10 @@ #include "scenetool.hpp" +class QFrame; +class QTableWidget; +class QModelIndex; + namespace CSVWidget { class SceneToolRun : public SceneTool @@ -17,6 +21,8 @@ namespace CSVWidget QString mToolTip; QString mIcon; QString mIconDisabled; + QFrame *mPanel; + QTableWidget *mTable; private: @@ -24,6 +30,8 @@ namespace CSVWidget void updateIcon(); + void updatePanel(); + public: SceneToolRun (SceneToolbar *parent, const QString& toolTip, const QString& icon, @@ -33,8 +41,14 @@ namespace CSVWidget virtual void activate(); + /// \attention This function does not remove the profile from the profile selection + /// panel. void removeProfile (const std::string& profile); + private slots: + + void clicked (const QModelIndex& index); + signals: void runRequest (const std::string& profile);