mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-19 21:53:51 +00:00
added profile selection panel
This commit is contained in:
parent
4337d05126
commit
3f24593dba
2 changed files with 76 additions and 0 deletions
|
@ -1,6 +1,12 @@
|
|||
|
||||
#include "scenetoolrun.hpp"
|
||||
|
||||
#include <QFrame>
|
||||
#include <QTableWidget>
|
||||
#include <QHBoxLayout>
|
||||
#include <QHeaderView>
|
||||
#include <QApplication>
|
||||
|
||||
void CSVWidget::SceneToolRun::adjustToolTips()
|
||||
{
|
||||
QString toolTip = mToolTip;
|
||||
|
@ -8,7 +14,10 @@ void CSVWidget::SceneToolRun::adjustToolTips()
|
|||
if (mCurrentIndex==-1)
|
||||
toolTip += "<p>No debug profile selected (function disabled)";
|
||||
else
|
||||
{
|
||||
toolTip += "<p>Debug profile: " + QString::fromUtf8 (mProfiles[mCurrentIndex].c_str());
|
||||
toolTip += "<p>(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<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,
|
||||
const QString& icon, const QString& iconDisabled, const std::vector<std::string>& 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();
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue