1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-01-24 06:23:54 +00:00
openmw/apps/opencs/view/widget/scenetoolrun.cpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

151 lines
3.7 KiB
C++
Raw Normal View History

#include "scenetoolrun.hpp"
2014-09-13 16:53:35 +00:00
#include <iterator>
2014-09-07 12:40:50 +00:00
#include <QApplication>
#include <QFrame>
#include <QHBoxLayout>
#include <QHeaderView>
#include <QTableWidget>
void CSVWidget::SceneToolRun::adjustToolTips()
{
QString toolTip = mToolTip;
2014-09-13 16:53:35 +00:00
if (mSelected == mProfiles.end())
toolTip += "<p>No debug profile selected (function disabled)";
else
2014-09-07 12:40:50 +00:00
{
2014-09-13 16:53:35 +00:00
toolTip += "<p>Debug profile: " + QString::fromUtf8(mSelected->c_str());
2014-09-07 12:40:50 +00:00
toolTip += "<p>(right click to switch to a different profile)";
}
setToolTip(toolTip);
}
void CSVWidget::SceneToolRun::updateIcon()
{
2014-11-27 08:27:29 +00:00
setDisabled(mSelected == mProfiles.end());
}
2014-09-07 12:40:50 +00:00
void CSVWidget::SceneToolRun::updatePanel()
{
2021-05-02 06:43:44 +00:00
mTable->setRowCount(static_cast<int>(mProfiles.size()));
2014-09-07 12:40:50 +00:00
2014-09-13 16:53:35 +00:00
int i = 0;
for (std::set<std::string>::const_iterator iter(mProfiles.begin()); iter != mProfiles.end(); ++iter, ++i)
2014-09-07 12:40:50 +00:00
{
2014-09-13 16:53:35 +00:00
mTable->setItem(i, 0, new QTableWidgetItem(QString::fromUtf8(iter->c_str())));
2014-09-07 12:40:50 +00:00
mTable->setItem(
i, 1, new QTableWidgetItem(QApplication::style()->standardIcon(QStyle::SP_TitleBarCloseButton), ""));
}
}
CSVWidget::SceneToolRun::SceneToolRun(
2014-11-27 08:27:29 +00:00
SceneToolbar* parent, const QString& toolTip, const QString& icon, const std::vector<std::string>& profiles)
2014-09-13 16:53:35 +00:00
: SceneTool(parent, Type_TopAction)
, mProfiles(profiles.begin(), profiles.end())
2014-11-27 08:27:29 +00:00
, mSelected(mProfiles.begin())
, mToolTip(toolTip)
{
2014-11-27 08:27:29 +00:00
setIcon(QIcon(icon));
updateIcon();
adjustToolTips();
2014-09-07 12:40:50 +00:00
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()->setSectionResizeMode(0, QHeaderView::Stretch);
mTable->horizontalHeader()->setSectionResizeMode(1, QHeaderView::ResizeToContents);
2014-09-07 12:40:50 +00:00
mTable->setSelectionMode(QAbstractItemView::NoSelection);
layout->addWidget(mTable);
connect(mTable, &QTableWidget::clicked, this, &SceneToolRun::clicked);
}
void CSVWidget::SceneToolRun::showPanel(const QPoint& position)
{
2014-09-07 12:40:50 +00:00
updatePanel();
2014-09-07 12:40:50 +00:00
mPanel->move(position);
mPanel->show();
}
void CSVWidget::SceneToolRun::activate()
{
2014-09-13 16:53:35 +00:00
if (mSelected != mProfiles.end())
emit runRequest(*mSelected);
}
void CSVWidget::SceneToolRun::removeProfile(const std::string& profile)
{
2014-09-13 16:53:35 +00:00
std::set<std::string>::iterator iter = mProfiles.find(profile);
2014-09-13 16:53:35 +00:00
if (iter != mProfiles.end())
{
2014-09-13 16:53:35 +00:00
if (iter == mSelected)
{
if (iter != mProfiles.begin())
--mSelected;
else
++mSelected;
}
mProfiles.erase(iter);
if (mSelected == mProfiles.end())
updateIcon();
adjustToolTips();
}
}
2014-09-13 16:53:35 +00:00
void CSVWidget::SceneToolRun::addProfile(const std::string& profile)
{
std::set<std::string>::iterator iter = mProfiles.find(profile);
if (iter == mProfiles.end())
{
mProfiles.insert(profile);
2014-09-13 16:53:35 +00:00
if (mSelected == mProfiles.end())
{
mSelected = mProfiles.begin();
updateIcon();
2014-09-13 16:53:35 +00:00
}
adjustToolTips();
}
2014-09-07 12:40:50 +00:00
}
void CSVWidget::SceneToolRun::clicked(const QModelIndex& index)
{
if (index.column() == 0)
{
// select profile
2014-09-13 16:53:35 +00:00
mSelected = mProfiles.begin();
std::advance(mSelected, index.row());
2014-09-07 12:40:50 +00:00
mPanel->hide();
adjustToolTips();
}
else if (index.column() == 1)
{
// remove profile from list
2014-09-13 16:53:35 +00:00
std::set<std::string>::iterator iter = mProfiles.begin();
std::advance(iter, index.row());
removeProfile(*iter);
2014-09-07 12:40:50 +00:00
updatePanel();
}
2015-03-11 14:54:45 +00:00
}