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

151 lines
3.7 KiB
C++
Raw Normal View History

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