Commit b3b1d8f2 authored by Victor Yacovlev's avatar Victor Yacovlev

New status bar

parent c8744a94
......@@ -12,3 +12,9 @@ scripts/*.pyo
.settings
.idea
*qtcreator*
/share/kumir2/python3language/__pycache__/run.cpython-33.pyc
/share/kumir2/python3language/__pycache__/analizer.cpython-33.pyc
/scripts/cpplint.py
/rules.txt
/artwork/userdocs_graphics/kumir_language/table_expressions_formulas.odg
/src/app/main.cpp.orig
This diff is collapsed.
......@@ -15,6 +15,7 @@ set(SOURCES
tabbar.cpp
aboutdialog.cpp
debuggerwindow.cpp
statusbar.cpp
)
set(EXTRA_LIBS
......@@ -40,6 +41,7 @@ set(MOC_HEADERS
aboutdialog.h
tabwidgetelement.h
debuggerwindow.h
statusbar.h
)
set(FORMS
......
......@@ -5,6 +5,7 @@
#include "aboutdialog.h"
#include "kumirprogram.h"
#include "dataformats/kumfile.h"
#include "statusbar.h"
#include <algorithm>
......@@ -15,8 +16,11 @@ namespace CoreGUI {
MainWindow::MainWindow(Plugin * p) :
QMainWindow(0),
ui(new Ui::MainWindow),
m_plugin(p)
m_plugin(p),
statusBar_(new StatusBar)
{
setMinimumHeight(280);
setStatusBar(statusBar_);
b_notabs = false;
b_workspaceSwitching = false;
......@@ -74,29 +78,29 @@ MainWindow::MainWindow(Plugin * p) :
setCorner(Qt::TopLeftCorner, Qt::LeftDockWidgetArea);
setCorner(Qt::TopRightCorner, Qt::RightDockWidgetArea);
statusBar()->setStyleSheet(
"QStatusBar { "
" border-top: 1px solid darkgray;"
"}"
"QToolButton {"
" icon-size: 16px;"
" border: none;"
"}"
);
setMinimumSize(980, 480);
statusBar()->addWidget(m_plugin->m_kumirStateLabel);
statusBar()->addWidget(m_plugin->m_genericCounterLabel);
m_plugin->m_kumirStateLabel->setFixedWidth(140);
m_plugin->m_kumirStateLabel->setStyleSheet(StatusbarWidgetCSS);
m_plugin->m_kumirStateLabel->setAlignment(Qt::AlignCenter);
m_plugin->m_genericCounterLabel->setFixedWidth(260);
m_plugin->m_genericCounterLabel->setStyleSheet(StatusbarWidgetCSS);
m_plugin->m_genericCounterLabel->setAlignment(Qt::AlignCenter);
m_message = new QLabel(this);
m_message->setAlignment(Qt::AlignCenter);
m_message->setStyleSheet(StatusbarWidgetCSS);
statusBar()->addWidget(m_message, 1);
// statusBar()->setStyleSheet(
// "QStatusBar { "
// " border-top: 1px solid darkgray;"
// "}"
// "QToolButton {"
// " icon-size: 16px;"
// " border: none;"
// "}"
// );
//// setMinimumSize(980, 480);
// statusBar()->addWidget(m_plugin->m_kumirStateLabel);
// statusBar()->addWidget(m_plugin->m_genericCounterLabel);
// m_plugin->m_kumirStateLabel->setFixedWidth(140);
// m_plugin->m_kumirStateLabel->setStyleSheet(StatusbarWidgetCSS);
// m_plugin->m_kumirStateLabel->setAlignment(Qt::AlignCenter);
// m_plugin->m_genericCounterLabel->setFixedWidth(260);
// m_plugin->m_genericCounterLabel->setStyleSheet(StatusbarWidgetCSS);
// m_plugin->m_genericCounterLabel->setAlignment(Qt::AlignCenter);
// m_message = new QLabel(this);
// m_message->setAlignment(Qt::AlignCenter);
// m_message->setStyleSheet(StatusbarWidgetCSS);
// statusBar()->addWidget(m_message, 1);
i_timerId = startTimer(1000);
......@@ -127,14 +131,14 @@ MainWindow::MainWindow(Plugin * p) :
ui->tabWidget->installEventFilter(this);
}
QString MainWindow::StatusbarWidgetCSS =
"QLabel {"
" font-size: 16px;"
" padding: 4px;"
" border: 2px solid darkgray;"
" margin: 0;"
"}"
;
//QString MainWindow::StatusbarWidgetCSS =
// "QLabel {"
// " font-size: 16px;"
// " padding: 4px;"
// " border: 2px solid darkgray;"
// " margin: 0;"
// "}"
//;
void MainWindow::changeFocusOnMenubar()
{
......@@ -309,21 +313,23 @@ void MainWindow::checkCounterValue()
if (twe->type==Program) {
int id = twe->documentId;
quint32 errorsCount = m_plugin->plugin_editor->errorsLinesCount(id);
if (errorsCount==0) {
m_plugin->m_genericCounterLabel->setText(tr("No errors"));
m_plugin->m_genericCounterLabel->setStyleSheet(StatusbarWidgetCSS);
}
else {
m_plugin->m_genericCounterLabel->setText(tr("Errors: %1").arg(errorsCount));
m_plugin->m_genericCounterLabel->setStyleSheet(StatusbarWidgetCSS+
"QLabel {"
" color: red;"
"}"
);
}
statusBar_->setErrorsCounter(errorsCount);
// if (errorsCount==0) {
// m_plugin->m_genericCounterLabel->setText(tr("No errors"));
// m_plugin->m_genericCounterLabel->setStyleSheet(StatusbarWidgetCSS);
// }
// else {
// m_plugin->m_genericCounterLabel->setText(tr("Errors: %1").arg(errorsCount));
// m_plugin->m_genericCounterLabel->setStyleSheet(StatusbarWidgetCSS+
// "QLabel {"
// " color: red;"
// "}"
// );
// }
}
else {
m_plugin->m_genericCounterLabel->setText("");
statusBar_->setErrorsCounter(0);
// m_plugin->m_genericCounterLabel->setText("");
}
}
else {
......@@ -338,9 +344,10 @@ void MainWindow::checkCounterValue()
if (stepsCounted == 0) {
stepsDone = 0; // just begin of evaluation
}
const QString text = tr("Steps done: %1").arg(stepsDone);
m_plugin->m_genericCounterLabel->setText(text);
m_plugin->m_genericCounterLabel->setStyleSheet(StatusbarWidgetCSS);
statusBar_->setStepsDoneCounter(stepsDone);
// const QString text = tr("Steps done: %1").arg(stepsDone);
// m_plugin->m_genericCounterLabel->setText(text);
// m_plugin->m_genericCounterLabel->setStyleSheet(StatusbarWidgetCSS);
}
}
}
......@@ -349,12 +356,14 @@ void MainWindow::checkCounterValue()
void MainWindow::showMessage(const QString &text)
{
m_message->setText(text);
statusBar_->setMessage(text);
// m_message->setText(text);
}
void MainWindow::clearMessage()
{
m_message->setText("");
statusBar_->unsetMessage();
// m_message->setText("");
}
void MainWindow::setFocusOnCentralWidget()
......@@ -427,18 +436,29 @@ void MainWindow::setupActionsForTab()
void MainWindow::setupStatusbarForTab()
{
foreach (QWidget * w, l_tabDependentStatusbarWidgets) {
statusBar()->removeWidget(w);
for (int i=0; i<ui->tabWidget->count(); i++) {
TabWidgetElement * w =
qobject_cast<TabWidgetElement*>(ui->tabWidget->widget(i));
if (w && w->component) {
w->component->disconnect(statusBar_);
}
}
QWidget * currentTabWidget = ui->tabWidget->currentWidget();
if (!currentTabWidget)
return;
TabWidgetElement * twe = qobject_cast<TabWidgetElement*>(currentTabWidget);
foreach (QWidget * w, twe->statusbarWidgets) {
l_tabDependentStatusbarWidgets << w;
w->setStyleSheet(StatusbarWidgetCSS);
statusBar()->addPermanentWidget(w);
w->show();
if (twe->type == Program || twe->type == Text) {
connect(twe->component,
SIGNAL(cursorPositionChanged(uint,uint)),
statusBar_,
SLOT(setEditorCursorPosition(uint,uint))
);
connect(twe->component,
SIGNAL(keyboardLayoutChanged(QLocale::Language,bool,bool,bool)),
statusBar_,
SLOT(setEditorKeyboardLayout(QLocale::Language,bool,bool,bool))
);
}
}
......@@ -746,7 +766,7 @@ void MainWindow::newProgram()
vc,
doc.toolbarActions,
doc.menus,
doc.statusbarWidgets,
// doc.statusbarWidgets,
type,
true);
e->documentId = doc.id;
......@@ -775,7 +795,7 @@ void MainWindow::newText(const QString &fileName, const QString & text)
vc,
doc.toolbarActions,
doc.menus,
doc.statusbarWidgets,
// doc.statusbarWidgets,
Text,
true);
e->documentId = doc.id;
......@@ -814,7 +834,7 @@ TabWidgetElement * MainWindow::addCentralComponent(
, QWidget *c
, const QList<QAction*> & toolbarActions
, const QList<QMenu*> & menus
, const QList<QWidget*> & statusbarWidgets
// , const QList<QWidget*> & statusbarWidgets
, DocumentType type
, bool enableToolBar)
{
......@@ -828,7 +848,7 @@ TabWidgetElement * MainWindow::addCentralComponent(
enableToolBar,
toolbarActions,
menus,
statusbarWidgets,
// statusbarWidgets,
type,
gr_fileActions,
gr_otherActions,
......@@ -990,7 +1010,7 @@ void MainWindow::restoreSession()
m_plugin->startPage_.widget,
m_plugin->startPage_.toolbarActions,
m_plugin->startPage_.menus,
QList<QWidget*>(),
// QList<QWidget*>(),
WWW,
false);
}
......@@ -1033,7 +1053,7 @@ void MainWindow::restoreSession()
vc,
doc.toolbarActions,
doc.menus,
doc.statusbarWidgets,
// doc.statusbarWidgets,
doctype,
true
);
......@@ -1452,7 +1472,7 @@ TabWidgetElement * MainWindow::loadFromUrl(const QUrl & url, bool addToRecentFil
vc,
doc.toolbarActions,
doc.menus,
doc.statusbarWidgets,
// doc.statusbarWidgets,
Program,
true);
result->documentId = id;
......@@ -1485,7 +1505,7 @@ TabWidgetElement * MainWindow::loadFromUrl(const QUrl & url, bool addToRecentFil
vc,
doc.toolbarActions,
doc.menus,
doc.statusbarWidgets,
// doc.statusbarWidgets,
Text,
true);
result->documentId = id;
......@@ -1504,7 +1524,7 @@ TabWidgetElement * MainWindow::loadFromUrl(const QUrl & url, bool addToRecentFil
browser.widget,
browser.toolbarActions,
browser.menus,
QList<QWidget*>(),
// QList<QWidget*>(),
WWW,
true);
result->url = url;
......@@ -1556,7 +1576,7 @@ TabWidgetElement* MainWindow::loadFromCourseManager(
vc,
toolBarActions,
menus,
doc.statusbarWidgets,
// doc.statusbarWidgets,
Program,
true
);
......
......@@ -36,7 +36,7 @@ public:
, QWidget *c
, const QList<QAction*> & toolbarActions
, const QList<QMenu*> & menus
, const QList<QWidget*> & statusbarWidgets
// , const QList<QWidget*> & statusbarWidgets
, DocumentType type
, bool enableToolBar);
......@@ -120,12 +120,13 @@ private:
bool b_notabs;
static QString StatusbarWidgetCSS;
// static QString StatusbarWidgetCSS;
QLabel * m_message;
Ui::MainWindow *ui;
Plugin *m_plugin;
class StatusBar * statusBar_;
};
......
......@@ -122,7 +122,6 @@
<addaction name="menuWindow"/>
<addaction name="menuHelp"/>
</widget>
<widget class="QStatusBar" name="statusBar"/>
<action name="actionNewProgram">
<property name="text">
<string>New program</string>
......
......@@ -4,6 +4,7 @@
#include "widgets/secondarywindow.h"
#include "debuggerwindow.h"
#include "ui_mainwindow.h"
#include "statusbar.h"
#ifdef Q_OS_MACX
#include "mac-fixes.h"
#endif
......@@ -75,9 +76,9 @@ QString Plugin::initialize(const QStringList & parameters)
const QStringList BlacklistedThemes = QStringList()
<< "iaorakde" << "iaoraqt" << "iaora";
const QString currentStyleName = qApp->style()->objectName().toLower();
if (BlacklistedThemes.contains(currentStyleName)) {
// if (BlacklistedThemes.contains(currentStyleName)) {
qApp->setStyle("Cleanlooks");
}
// }
QString iconSuffix;
for (int i=0; i<parameters.count(); i++) {
......@@ -150,22 +151,22 @@ QString Plugin::initialize(const QStringList & parameters)
// termWindow->toggleViewAction()->setShortcut(QKeySequence("F12"));
#endif
QToolButton * btnSaveTerm = new QToolButton(mainWindow_);
btnSaveTerm->setPopupMode(QToolButton::InstantPopup);
QMenu * menuSaveTerm = new QMenu(btnSaveTerm);
btnSaveTerm->setMenu(menuSaveTerm);
btnSaveTerm->setIcon(m_terminal->actionSaveLast()->icon());
menuSaveTerm->addAction(m_terminal->actionSaveLast());
menuSaveTerm->addAction(m_terminal->actionSaveAll());
mainWindow_->statusBar()->insertWidget(0, btnSaveTerm);
QToolButton * btnClearTerm = new QToolButton(mainWindow_);
btnClearTerm->setDefaultAction(m_terminal->actionClear());
mainWindow_->statusBar()->insertWidget(1, btnClearTerm);
if (!parameters.contains("notabs",Qt::CaseInsensitive)) {
QToolButton * btnEditTerm = new QToolButton(mainWindow_);
btnEditTerm->setDefaultAction(m_terminal->actionEditLast());
mainWindow_->statusBar()->insertWidget(1, btnEditTerm);
}
// QToolButton * btnSaveTerm = new QToolButton(mainWindow_);
// btnSaveTerm->setPopupMode(QToolButton::InstantPopup);
// QMenu * menuSaveTerm = new QMenu(btnSaveTerm);
// btnSaveTerm->setMenu(menuSaveTerm);
// btnSaveTerm->setIcon(m_terminal->actionSaveLast()->icon());
// menuSaveTerm->addAction(m_terminal->actionSaveLast());
// menuSaveTerm->addAction(m_terminal->actionSaveAll());
// mainWindow_->statusBar()->insertWidget(0, btnSaveTerm);
// QToolButton * btnClearTerm = new QToolButton(mainWindow_);
// btnClearTerm->setDefaultAction(m_terminal->actionClear());
// mainWindow_->statusBar()->insertWidget(1, btnClearTerm);
// if (!parameters.contains("notabs",Qt::CaseInsensitive)) {
// QToolButton * btnEditTerm = new QToolButton(mainWindow_);
// btnEditTerm->setDefaultAction(m_terminal->actionEditLast());
// mainWindow_->statusBar()->insertWidget(1, btnEditTerm);
// }
kumirProgram_ = new KumirProgram(this);
......@@ -436,34 +437,34 @@ void Plugin::updateSettings()
void Plugin::changeGlobalState(ExtensionSystem::GlobalState old, ExtensionSystem::GlobalState state)
{
if (state==ExtensionSystem::GS_Unlocked) {
m_kumirStateLabel->setText(tr("Editing"));
// m_kumirStateLabel->setText(tr("Editing"));
mainWindow_->clearMessage();
mainWindow_->setFocusOnCentralWidget();
mainWindow_->unlockActions();
debugger_->reset();
}
else if (state==ExtensionSystem::GS_Observe) {
m_kumirStateLabel->setText(tr("Observe"));
// m_kumirStateLabel->setText(tr("Observe"));
mainWindow_->showMessage(kumirProgram_->endStatus());
mainWindow_->setFocusOnCentralWidget();
mainWindow_->unlockActions();
}
else if (state==ExtensionSystem::GS_Running) {
m_kumirStateLabel->setText(tr("Running"));
// m_kumirStateLabel->setText(tr("Running"));
mainWindow_->clearMessage();
mainWindow_->lockActions();
}
else if (state==ExtensionSystem::GS_Pause) {
m_kumirStateLabel->setText(tr("Pause"));
// m_kumirStateLabel->setText(tr("Pause"));
mainWindow_->lockActions();
}
else if (state==ExtensionSystem::GS_Input) {
m_kumirStateLabel->setText(tr("Pause"));
// m_kumirStateLabel->setText(tr("Pause"));
mainWindow_->lockActions();
}
kumirProgram_->switchGlobalState(old, state);
m_terminal->changeGlobalState(old, state);
mainWindow_->statusBar_->setState(state);
}
......@@ -519,7 +520,7 @@ void Plugin::restoreSession()
startPage_.widget,
startPage_.toolbarActions,
startPage_.menus,
QList<QWidget*>(),
// QList<QWidget*>(),
MainWindow::WWW,
false
);
......
......@@ -4,5 +4,7 @@
<file>close-tab.png</file>
<file>horizontal-splitter-background.png</file>
<file>horizontal-splitter-handle.png</file>
<file>statusbar_alt_indicator.png</file>
<file>statusbar_shift_indicator.png</file>
</qresource>
</RCC>
#include "statusbar.h"
#include <QPaintEvent>
#include <QPainter>
#include <QPalette>
#include <QBrush>
#include <QPen>
#include <QColor>
#include <QStyle>
#include <QStyleOption>
#include <QStyleOptionFrameV3>
namespace CoreGUI {
static const int ItemPadding = 8;
StatusBar::StatusBar(QWidget *parent)
: QStatusBar(parent)
, state_(ExtensionSystem::GS_Unlocked)
, errorsCount_(0u)
, stepsDone_(0u)
, messageRole_(Normal)
, editorRow_(0u)
, editorColumn_(0u)
, keyboardLayout_(QLocale::C)
, keyboardCaps_(false)
, keyboardShift_(false)
, keyboardAlt_(false)
{
}
QSize StatusBar::minimumSizeHint() const
{
int h = 0;
int w = 0;
h = qMax(h, modeItemSize().height());
w += modeItemSize().width();
h = qMax(h, counterItemSize().height());
w += counterItemSize().width();
h = qMax(h, cursorPositionItemSize().height());
w += cursorPositionItemSize().width();
h = qMax(h, keyboardLayoutItemSize().height());
w += keyboardLayoutItemSize().width();
return QSize(w, h);
}
void StatusBar::setState(ExtensionSystem::GlobalState state)
{
state_ = state;
update();
}
void StatusBar::setMessage(const QString &message, MessageRole role)
{
message_ = message;
messageRole_ = role;
update();
}
void StatusBar::unsetMessage()
{
message_.clear();
messageRole_ = Normal;
update();
}
void StatusBar::setStepsDoneCounter(uint value)
{
stepsDone_ = value;
update();
}
void StatusBar::setErrorsCounter(uint value)
{
errorsCount_ = value;
update();
}
void StatusBar::setEditorCursorPosition(uint row, uint column)
{
editorRow_ = row;
editorColumn_ = column;
update();
}
void StatusBar::setEditorKeyboardLayout(QLocale::Language lang, bool capslock, bool shift, bool alt)
{
keyboardLayout_ = lang;
keyboardCaps_ = capslock;
keyboardShift_ = shift;
keyboardAlt_ = alt;
update();
}
QSize StatusBar::keyboardLayoutItemSize() const
{
static const QStringList items = QStringList()
<< tr("rus") << tr("rus").toUpper()
<< tr("lat") << tr("lat").toUpper();
int maxTextWidth = 0;
const int textHeight = statusBarFontMetrics().height();
foreach (const QString &text, items) {
maxTextWidth = qMax(maxTextWidth, statusBarFontMetrics().width(text));
}
const int width = 2*(12 + 1) + maxTextWidth;
const int height = qMax(14, textHeight);
return QSize(width + 2*ItemPadding, height);
}
QSize StatusBar::cursorPositionItemSize() const
{
static const QString text = tr("Row: ww, Col.: ww");
return QSize(statusBarFontMetrics().width(text) + 2 * ItemPadding,
qMax(14, statusBarFontMetrics().height()));
}
QSize StatusBar::modeItemSize() const
{
static QStringList items = QStringList()
<< tr("Edit") << tr("Analisys") << tr("Run") << tr("Pause");
int maxTextWidth = 0;
const int textHeight = statusBarFontMetrics().height();
foreach (const QString &text, items) {
maxTextWidth = qMax(maxTextWidth, statusBarFontMetrics().width(text));
}
const int height = qMax(14, textHeight);
return QSize(maxTextWidth + 2*ItemPadding, height);
}
QSize StatusBar::counterItemSize() const
{
static const QString errorsText = tr("ww errors");
static const QString noErrorsText = tr("No errors");
static const QString stepsDoneText = tr("wwwww steps done");
const int textHeight = statusBarFontMetrics().height();
int maxTextWidthEdit = 0;
maxTextWidthEdit = qMax(maxTextWidthEdit, statusBarFontMetrics().width(errorsText));
maxTextWidthEdit = qMax(maxTextWidthEdit, statusBarFontMetrics().width(noErrorsText));
int textWidthOther = statusBarFontMetrics().width(stepsDoneText);
const int textWidth = state_ == ExtensionSystem::GS_Unlocked
? maxTextWidthEdit : textWidthOther;
const int height = qMax(14, textHeight);
return QSize(textWidth + 2*ItemPadding, height);
}
QSize StatusBar::messageItemSize() const
{
const int textHeight = statusBarFontMetrics().height();
const int messageWidth = statusBarFontMetrics().width(message_);
const int height = qMax(14, textHeight);
return QSize(messageWidth + 2*ItemPadding,