Fix issues with running scripts window on Windows

Replace running scripts table with a new widget that uses a proper
layout that doesn't rely on hard-coded sizing.  Custom painted lines
were replaced with a horizontal QFrame line.
This commit is contained in:
Ryan Huffman 2014-06-17 20:19:49 -07:00
parent 5ef9e3b3c0
commit 0877f9f159
3 changed files with 116 additions and 150 deletions

View file

@ -27,6 +27,7 @@
RunningScriptsWidget::RunningScriptsWidget(QWidget* parent) :
FramelessDialog(parent, 0, POSITION_LEFT),
ui(new Ui::RunningScriptsWidget),
_signalMapper(this),
_scriptsModel(this),
_proxyModel(this) {
ui->setupUi(this);
@ -55,17 +56,9 @@ RunningScriptsWidget::RunningScriptsWidget(QWidget* parent) :
connect(ui->filterLineEdit, &QLineEdit::textChanged, this, &RunningScriptsWidget::updateFileFilter);
connect(ui->scriptListView, &QListView::doubleClicked, this, &RunningScriptsWidget::loadScriptFromList);
_runningScriptsTable = new ScriptsTableWidget(ui->runningScriptsTableWidget);
_runningScriptsTable->setColumnCount(2);
_runningScriptsTable->setColumnWidth(0, 245);
_runningScriptsTable->setColumnWidth(1, 22);
connect(_runningScriptsTable, &QTableWidget::cellClicked, this, &RunningScriptsWidget::stopScript);
_recentlyLoadedScriptsTable = new ScriptsTableWidget(ui->recentlyLoadedScriptsTableWidget);
_recentlyLoadedScriptsTable->setColumnCount(1);
_recentlyLoadedScriptsTable->setColumnWidth(0, 265);
connect(_recentlyLoadedScriptsTable, &QTableWidget::cellClicked,
this, &RunningScriptsWidget::loadScript);
connect(ui->hideWidgetButton, &QPushButton::clicked,
Application::getInstance(), &Application::toggleRunningScriptsWidget);
@ -75,6 +68,7 @@ RunningScriptsWidget::RunningScriptsWidget(QWidget* parent) :
this, &RunningScriptsWidget::allScriptsStopped);
connect(ui->loadScriptButton, &QPushButton::clicked,
Application::getInstance(), &Application::loadDialog);
connect(&_signalMapper, SIGNAL(mapped(QString)), Application::getInstance(), SLOT(stopScript(const QString&)));
}
RunningScriptsWidget::~RunningScriptsWidget() {
@ -104,45 +98,55 @@ void RunningScriptsWidget::setBoundary(const QRect& rect) {
}
void RunningScriptsWidget::setRunningScripts(const QStringList& list) {
_runningScriptsTable->setRowCount(list.size());
setUpdatesEnabled(false);
QLayoutItem* widget;
while ((widget = ui->scrollAreaWidgetContents->layout()->takeAt(0)) != NULL) {
delete widget->widget();
delete widget;
}
const int CLOSE_ICON_HEIGHT = 12;
for (int i = 0; i < list.size(); i++) {
QWidget* row = new QWidget(ui->scrollAreaWidgetContents);
row->setLayout(new QHBoxLayout(row));
QUrl url = QUrl(list.at(i));
QLabel* name = new QLabel(url.fileName(), row);
QPushButton* closeButton = new QPushButton(row);
closeButton->setFlat(true);
closeButton->setIcon(
QIcon(QPixmap(Application::resourcesPath() + "images/kill-script.svg").scaledToHeight(CLOSE_ICON_HEIGHT)));
closeButton->setSizePolicy(QSizePolicy(QSizePolicy::Maximum, QSizePolicy::Preferred));
closeButton->setStyleSheet("border: 0;");
closeButton->setCursor(Qt::PointingHandCursor);
connect(closeButton, SIGNAL(clicked()), &_signalMapper, SLOT(map()));
_signalMapper.setMapping(closeButton, url.toString());
row->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed));
row->layout()->setContentsMargins(4, 4, 4, 4);
row->layout()->setSpacing(0);
row->layout()->addWidget(name);
row->layout()->addWidget(closeButton);
QFrame* line = new QFrame(row);
line->setFrameShape(QFrame::HLine);
line->setStyleSheet("color: #E1E1E1; margin-left: 6px; margin-right: 6px;");
ui->scrollAreaWidgetContents->layout()->addWidget(row);
ui->scrollAreaWidgetContents->layout()->addWidget(line);
}
ui->noRunningScriptsLabel->setVisible(list.isEmpty());
ui->runningScriptsTableWidget->setVisible(!list.isEmpty());
ui->reloadAllButton->setVisible(!list.isEmpty());
ui->stopAllButton->setVisible(!list.isEmpty());
const int CLOSE_ICON_HEIGHT = 12;
for (int i = 0; i < list.size(); ++i) {
QTableWidgetItem *scriptName = new QTableWidgetItem;
scriptName->setText(QFileInfo(list.at(i)).fileName());
scriptName->setToolTip(list.at(i));
scriptName->setTextAlignment(Qt::AlignLeft | Qt::AlignVCenter);
QTableWidgetItem *closeIcon = new QTableWidgetItem;
closeIcon->setIcon(QIcon(QPixmap(Application::resourcesPath() + "images/kill-script.svg").scaledToHeight(CLOSE_ICON_HEIGHT)));
_runningScriptsTable->setItem(i, 0, scriptName);
_runningScriptsTable->setItem(i, 1, closeIcon);
}
const int RUNNING_SCRIPTS_TABLE_LEFT_MARGIN = 12;
const int RECENTLY_LOADED_TOP_MARGIN = 61;
const int RECENTLY_LOADED_LABEL_TOP_MARGIN = 19;
int y = ui->runningScriptsTableWidget->y() + RUNNING_SCRIPTS_TABLE_LEFT_MARGIN;
for (int i = 0; i < _runningScriptsTable->rowCount(); ++i) {
y += _runningScriptsTable->rowHeight(i);
}
ui->runningScriptsTableWidget->resize(ui->runningScriptsTableWidget->width(), y - RUNNING_SCRIPTS_TABLE_LEFT_MARGIN);
_runningScriptsTable->resize(_runningScriptsTable->width(), y - RUNNING_SCRIPTS_TABLE_LEFT_MARGIN);
ui->recentlyLoadedLabel->move(ui->recentlyLoadedLabel->x(),
ui->stopAllButton->y() + ui->stopAllButton->height() + RECENTLY_LOADED_TOP_MARGIN);
ui->recentlyLoadedScriptsTableWidget->move(ui->recentlyLoadedScriptsTableWidget->x(),
ui->recentlyLoadedLabel->y() + RECENTLY_LOADED_LABEL_TOP_MARGIN);
createRecentlyLoadedScriptsTable();
ui->scrollAreaWidgetContents->updateGeometry();
setUpdatesEnabled(true);
Application::processEvents();
repaint();
}
void RunningScriptsWidget::showEvent(QShowEvent* event) {
@ -187,81 +191,10 @@ void RunningScriptsWidget::keyPressEvent(QKeyEvent *keyEvent) {
}
}
void RunningScriptsWidget::paintEvent(QPaintEvent* event) {
QPainter painter(this);
painter.setPen(QColor::fromRgb(225, 225, 225)); // #e1e1e1
const QPoint& labelPos = ui->runningScriptsArea->mapToParent(ui->currentlyRunningLabel->pos());
if (ui->currentlyRunningLabel->isVisible()) {
// line below the 'Currently Running' label
painter.drawLine(36, labelPos.y() + ui->currentlyRunningLabel->height(),
300, labelPos.y() + ui->currentlyRunningLabel->height());
}
if (ui->recentlyLoadedLabel->isVisible()) {
// line below the 'Recently loaded' label
painter.drawLine(36, ui->recentlyLoadedLabel->y() + ui->recentlyLoadedLabel->height(),
300, ui->recentlyLoadedLabel->y() + ui->recentlyLoadedLabel->height());
}
painter.end();
}
void RunningScriptsWidget::scriptStopped(const QString& scriptName) {
_recentlyLoadedScripts.prepend(scriptName);
}
void RunningScriptsWidget::stopScript(int row, int column) {
if (column == 1) { // make sure the user has clicked on the close icon
_lastStoppedScript = _runningScriptsTable->item(row, 0)->toolTip();
emit stopScriptName(_runningScriptsTable->item(row, 0)->toolTip());
}
}
void RunningScriptsWidget::loadScript(int row, int column) {
Application::getInstance()->loadScript(_recentlyLoadedScriptsTable->item(row, column)->toolTip(), false, false);
// _recentlyLoadedScripts.prepend(scriptName);
}
void RunningScriptsWidget::allScriptsStopped() {
Application::getInstance()->stopAllScripts();
}
void RunningScriptsWidget::createRecentlyLoadedScriptsTable() {
if (!_recentlyLoadedScripts.contains(_lastStoppedScript) && !_lastStoppedScript.isEmpty()) {
_recentlyLoadedScripts.prepend(_lastStoppedScript);
_lastStoppedScript = "";
}
for (int i = 0; i < _recentlyLoadedScripts.size(); ++i) {
if (Application::getInstance()->getRunningScripts().contains(_recentlyLoadedScripts.at(i))) {
_recentlyLoadedScripts.removeOne(_recentlyLoadedScripts.at(i));
}
}
ui->noRecentlyLoadedLabel->setVisible(_recentlyLoadedScripts.isEmpty());
ui->recentlyLoadedScriptsTableWidget->setVisible(!_recentlyLoadedScripts.isEmpty());
ui->recentlyLoadedInstruction->setVisible(!_recentlyLoadedScripts.isEmpty());
int limit = _recentlyLoadedScripts.size() > 9 ? 9 : _recentlyLoadedScripts.size();
_recentlyLoadedScriptsTable->setRowCount(limit);
for (int i = 0; i < limit; i++) {
QTableWidgetItem *scriptName = new QTableWidgetItem;
scriptName->setText(QString::number(i + 1) + ". " + QFileInfo(_recentlyLoadedScripts.at(i)).fileName());
scriptName->setToolTip(_recentlyLoadedScripts.at(i));
scriptName->setTextAlignment(Qt::AlignLeft | Qt::AlignVCenter);
_recentlyLoadedScriptsTable->setItem(i, 0, scriptName);
}
int y = ui->recentlyLoadedScriptsTableWidget->y() + 15;
for (int i = 0; i < _recentlyLoadedScriptsTable->rowCount(); ++i) {
y += _recentlyLoadedScriptsTable->rowHeight(i);
}
ui->recentlyLoadedInstruction->setGeometry(36, y,
ui->recentlyLoadedInstruction->width(),
ui->recentlyLoadedInstruction->height());
repaint();
}

View file

@ -14,6 +14,7 @@
#define hifi_RunningScriptsWidget_h
#include <QFileSystemModel>
#include <QSignalMapper>
#include <QSortFilterProxyModel>
#include "ScriptsModel.h"
@ -40,7 +41,6 @@ protected:
virtual bool eventFilter(QObject* sender, QEvent* event);
virtual void keyPressEvent(QKeyEvent* event);
virtual void paintEvent(QPaintEvent* event);
virtual void showEvent(QShowEvent* event);
public slots:
@ -48,8 +48,6 @@ public slots:
void setBoundary(const QRect& rect);
private slots:
void stopScript(int row, int column);
void loadScript(int row, int column);
void allScriptsStopped();
void updateFileFilter(const QString& filter);
void loadScriptFromList(const QModelIndex& index);
@ -58,15 +56,13 @@ private slots:
private:
Ui::RunningScriptsWidget* ui;
QSignalMapper _signalMapper;
QSortFilterProxyModel _proxyModel;
ScriptsModel _scriptsModel;
ScriptsTableWidget* _runningScriptsTable;
ScriptsTableWidget* _recentlyLoadedScriptsTable;
QStringList _recentlyLoadedScripts;
QString _lastStoppedScript;
QRect _boundary;
void createRecentlyLoadedScriptsTable();
};
#endif // hifi_RunningScriptsWidget_h

View file

@ -304,6 +304,9 @@ padding-top: 3px;</string>
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
@ -313,26 +316,73 @@ padding-top: 3px;</string>
</spacer>
</item>
<item>
<widget class="QWidget" name="runningScriptsTableWidget" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>1</verstretch>
</sizepolicy>
<widget class="QScrollArea" name="runningScriptsList">
<property name="font">
<font>
<family>Helvetica,Arial,sans-serif</family>
<pointsize>14</pointsize>
</font>
</property>
<property name="minimumSize">
<size>
<width>284</width>
<height>0</height>
</size>
</property>
<property name="toolTipDuration">
<number>0</number>
<property name="layoutDirection">
<enum>Qt::LeftToRight</enum>
</property>
<property name="styleSheet">
<string notr="true">background: transparent;
font-size: 14pt;</string>
<string notr="true">margin: 0;</string>
</property>
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="lineWidth">
<number>0</number>
</property>
<property name="verticalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOn</enum>
</property>
<property name="horizontalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOff</enum>
</property>
<property name="widgetResizable">
<bool>true</bool>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
</property>
<widget class="QWidget" name="scrollAreaWidgetContents">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>269</width>
<height>16</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Maximum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="styleSheet">
<string notr="true">font-size: 14pt;</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_5">
<property name="spacing">
<number>0</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
</layout>
</widget>
</widget>
</item>
</layout>
@ -410,20 +460,7 @@ font: bold 16pt;</string>
<string notr="true">background: transparent;
font-size: 14pt;</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="recentlyLoadedInstruction">
<property name="styleSheet">
<string notr="true">color: #95a5a6;
font-size: 14pt;</string>
</property>
<property name="text">
<string>(click a script or use the 1-9 keys to load and run it)</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
<zorder>runningScriptsList</zorder>
</widget>
</item>
</layout>