From 4b45c34ec08672b9d123b6b0b56b0304dcc69dcd Mon Sep 17 00:00:00 2001 From: Richard Pecl Date: Tue, 18 Nov 2014 23:13:13 +0100 Subject: [PATCH 1/4] bitfield widget is now dockable and sizable --- src/SourceFiles.cmake | 2 ++ src/core/settings.cpp | 4 +-- src/core/settings.h | 2 +- src/gui/bitfielddock.cpp | 51 ++++++++++++++++++++++++++++++ src/gui/bitfielddock.h | 48 ++++++++++++++++++++++++++++ src/gui/bitfieldwidget.cpp | 64 ++++++++++++++++++++++++++----------- src/gui/bitfieldwidget.h | 7 +++- src/gui/mainwindow.cpp | 65 +++++++++++++++++++++++++------------- src/gui/mainwindow.h | 10 +++--- src/speedcrunch.pro | 2 ++ 10 files changed, 205 insertions(+), 50 deletions(-) create mode 100644 src/gui/bitfielddock.cpp create mode 100644 src/gui/bitfielddock.h diff --git a/src/SourceFiles.cmake b/src/SourceFiles.cmake index 9e5d9fc1..16c52db0 100644 --- a/src/SourceFiles.cmake +++ b/src/SourceFiles.cmake @@ -9,6 +9,7 @@ core/evaluator.h core/functions.h core/manual.h gui/aboutbox.h +gui/bitfielddock.h gui/bitfieldwidget.h gui/bookdock.h gui/constantsdock.h @@ -39,6 +40,7 @@ core/numberformatter.cpp core/pageserver.cpp core/settings.cpp gui/aboutbox.cpp +gui/bitfielddock.cpp gui/bitfieldwidget.cpp gui/bookdock.cpp gui/constantsdock.cpp diff --git a/src/core/settings.cpp b/src/core/settings.cpp index 5164a8a7..794cfcf4 100644 --- a/src/core/settings.cpp +++ b/src/core/settings.cpp @@ -120,8 +120,8 @@ void Settings::load() userFunctionsDockVisible = settings->value(key + QLatin1String("UserFunctionsDockVisible"), false).toBool(); formulaBookDockVisible = settings->value(key + QLatin1String("FormulaBookDockVisible"), false).toBool(); constantsDockVisible = settings->value(key + QLatin1String("ConstantsDockVisible"), false).toBool(); + bitFieldDockVisible = settings->value(key + QLatin1String("bitFieldDockVisible"), false).toBool(); windowAlwaysOnTop = settings->value(key + QLatin1String("WindowAlwaysOnTop"), false).toBool(); - bitfieldVisible = settings->value(key + QLatin1String("BitfieldVisible"), false).toBool(); windowPosition = settings->value(key + QLatin1String("WindowPosition"), QPoint()).toPoint(); windowSize = settings->value(key + QLatin1String("WindowSize"), QSize(640, 480)).toSize(); @@ -263,12 +263,12 @@ void Settings::save() settings->setValue(key + QLatin1String("StatusBarVisible"), statusBarVisible); settings->setValue(key + QLatin1String("VariablesDockVisible"), variablesDockVisible); settings->setValue(key + QLatin1String("UserFunctionsDockVisible"), userFunctionsDockVisible); + settings->setValue(key + QLatin1String("bitFieldDockVisible"), bitFieldDockVisible); settings->setValue(key + QLatin1String("WindowPosition"), windowPosition); settings->setValue(key + QLatin1String("WindowSize"), windowSize); settings->setValue(key + QLatin1String("WindowAlwaysOnTop"), windowAlwaysOnTop); settings->setValue(key + QLatin1String("State"), windowState); settings->setValue(key + QLatin1String("Maximized"), maximized); - settings->setValue(key + QLatin1String("BitfieldVisible"), bitfieldVisible); key = KEY + QLatin1String("/Display/"); diff --git a/src/core/settings.h b/src/core/settings.h index 3de94172..ed1a48bd 100644 --- a/src/core/settings.h +++ b/src/core/settings.h @@ -67,8 +67,8 @@ class Settings { bool statusBarVisible; bool variablesDockVisible; bool userFunctionsDockVisible; + bool bitFieldDockVisible; bool windowOnfullScreen; - bool bitfieldVisible; int colorScheme; QString displayFont; diff --git a/src/gui/bitfielddock.cpp b/src/gui/bitfielddock.cpp new file mode 100644 index 00000000..b499bd45 --- /dev/null +++ b/src/gui/bitfielddock.cpp @@ -0,0 +1,51 @@ +// This file is part of the SpeedCrunch project +// Copyright (C) 2007 Ariya Hidayat +// Copyright (C) 2007, 2008, 2009, 2010 Helder Correia +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, +// Boston, MA 02110-1301, USA. + +#include "math/hmath.h" + +#include "gui/bitfielddock.h" +#include "gui/bitfieldwidget.h" + +#include + +BitFieldDock::BitFieldDock(QWidget *parent) + : QDockWidget(parent) + , m_widget(new BitFieldWidget(this)) +{ + setWidget( m_widget ); + retranslateText(); +} + +void BitFieldDock::updateBits(const HNumber& number) +{ + m_widget->updateBits(number); +} + +void BitFieldDock::retranslateText() +{ + setWindowTitle(tr("Bitfield")); +} + +void BitFieldDock::changeEvent(QEvent *e) +{ + if (e->type() == QEvent::LanguageChange) + retranslateText(); + else + QDockWidget::changeEvent(e); +} diff --git a/src/gui/bitfielddock.h b/src/gui/bitfielddock.h new file mode 100644 index 00000000..f8bf46aa --- /dev/null +++ b/src/gui/bitfielddock.h @@ -0,0 +1,48 @@ +// This file is part of the SpeedCrunch project +// Copyright (C) 2007 Ariya Hidayat +// Copyright (C) 2007, 2008, 2009, 2010 Helder Correia +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, +// Boston, MA 02110-1301, USA. + +#ifndef GUI_BITFIELDDOCK_H +#define GUI_BITFIELDDOCK_H + +#include + +class BitFieldWidget; +class HNumber; + +class BitFieldDock : public QDockWidget +{ + Q_OBJECT + +public: + BitFieldDock(QWidget *parent = 0); + +public slots: + void updateBits(const HNumber&); + +protected: + virtual void changeEvent(QEvent *); + void retranslateText(); + +private: + Q_DISABLE_COPY(BitFieldDock) + + BitFieldWidget *m_widget; +}; + +#endif // GUI_BITFIELDDOCK_H diff --git a/src/gui/bitfieldwidget.cpp b/src/gui/bitfieldwidget.cpp index 1e5221b5..aa98bdaa 100644 --- a/src/gui/bitfieldwidget.cpp +++ b/src/gui/bitfieldwidget.cpp @@ -27,20 +27,29 @@ #include #include #include -#include +#include + +//------------------------------------------------------------------------------ BitWidget::BitWidget(int bitPosition, QWidget* parent) : QLabel(parent), m_state(false) { - setFixedSize(SizePixels, SizePixels); - + setMinimumSize(SizePixels, SizePixels); + setMaximumSize(SizePixels*4, SizePixels*4); + setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Minimum); + HNumber number(HMath::raise(HNumber(2), bitPosition)); setToolTip(QString("2%1 = %2") .arg(bitPosition) .arg(HMath::format(number, 'd'))); } +QSize BitWidget::sizeHint() const +{ + return QSize(SizePixels*4, SizePixels*4); +} + void BitWidget::mouseReleaseEvent(QMouseEvent*) { setState(!m_state); @@ -58,6 +67,8 @@ void BitWidget::paintEvent(QPaintEvent* event) painter.drawRect(event->rect()); } +//------------------------------------------------------------------------------ + BitFieldWidget::BitFieldWidget(QWidget* parent) : QWidget(parent) { @@ -110,35 +121,50 @@ BitFieldWidget::BitFieldWidget(QWidget* parent) : } } - QPushButton* resetButton = new QPushButton("0"); - resetButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); + QToolButton* resetButton = new QToolButton(); + resetButton->setText("0"); + resetButton->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); connect(resetButton, SIGNAL(clicked()), this, SLOT(resetBits())); - QPushButton* invertButton = new QPushButton("~"); - invertButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); + QToolButton* invertButton = new QToolButton(); + invertButton->setText("~"); + invertButton->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); connect(invertButton, SIGNAL(clicked()), this, SLOT(invertBits())); - QPushButton* shiftLeftButton = new QPushButton("<<"); - shiftLeftButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); + QToolButton* shiftLeftButton = new QToolButton(); + shiftLeftButton->setText("<<"); + shiftLeftButton->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); connect(shiftLeftButton, SIGNAL(clicked()), this, SLOT(shiftBitsLeft())); - QPushButton* shiftRightButton = new QPushButton(">>"); - shiftRightButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); + QToolButton* shiftRightButton = new QToolButton(); + shiftRightButton->setText(">>"); + shiftRightButton->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); connect(shiftRightButton, SIGNAL(clicked()), this, SLOT(shiftBitsRight())); - QVBoxLayout* buttonsLayout = new QVBoxLayout; - buttonsLayout->addWidget(resetButton); - buttonsLayout->addWidget(shiftLeftButton); + int col = fieldLayout->columnCount(); + fieldLayout->addWidget(resetButton, 0, col); + fieldLayout->addWidget(shiftLeftButton, 1, col); + fieldLayout->addWidget(invertButton, 0, ++col); + fieldLayout->addWidget(shiftRightButton, 1, col); + + // add empty row eating as much as possible (no spacing between format rows) + fieldLayout->addWidget(new QWidget(), 2, 0, -1, -1); + fieldLayout->setRowStretch(2, 1); + + //QVBoxLayout* buttonsLayout = new QVBoxLayout; + //buttonsLayout->addWidget(resetButton); + //buttonsLayout->addWidget(shiftLeftButton); - QVBoxLayout* buttonsLayout2 = new QVBoxLayout; - buttonsLayout2->addWidget(invertButton); - buttonsLayout2->addWidget(shiftRightButton); + //QVBoxLayout* buttonsLayout2 = new QVBoxLayout; + //buttonsLayout2->addWidget(invertButton); + //buttonsLayout2->addWidget(shiftRightButton); QHBoxLayout* mainLayout = new QHBoxLayout(this); + mainLayout->setMargin(0); mainLayout->addStretch(); mainLayout->addLayout(fieldLayout); - mainLayout->addLayout(buttonsLayout); - mainLayout->addLayout(buttonsLayout2); + //mainLayout->addLayout(buttonsLayout); + //mainLayout->addLayout(buttonsLayout2); mainLayout->addStretch(); } diff --git a/src/gui/bitfieldwidget.h b/src/gui/bitfieldwidget.h index ce19645b..c1718485 100644 --- a/src/gui/bitfieldwidget.h +++ b/src/gui/bitfieldwidget.h @@ -25,11 +25,14 @@ class HNumber; +//------------------------------------------------------------------------------ + class BitWidget : public QLabel { Q_OBJECT public: explicit BitWidget(int apos, QWidget* parent = 0); + virtual QSize sizeHint() const; bool state() const { return m_state; } void setState(bool state) { m_state = state; update(); } @@ -43,7 +46,7 @@ class BitWidget : public QLabel { private: enum { - SizePixels = 20, + SizePixels = 5, }; Q_DISABLE_COPY(BitWidget) @@ -51,6 +54,8 @@ class BitWidget : public QLabel { bool m_state; }; +//------------------------------------------------------------------------------ + class BitFieldWidget : public QWidget { Q_OBJECT diff --git a/src/gui/mainwindow.cpp b/src/gui/mainwindow.cpp index 48b32330..60e0fd1c 100644 --- a/src/gui/mainwindow.cpp +++ b/src/gui/mainwindow.cpp @@ -28,7 +28,7 @@ #include "core/numberformatter.h" #include "core/settings.h" #include "gui/aboutbox.h" -#include "gui/bitfieldwidget.h" +#include "gui/bitfielddock.h" #include "gui/bookdock.h" #include "gui/constantsdock.h" #include "gui/editor.h" @@ -676,13 +676,20 @@ void MainWindow::createFixedWidgets() #endif // Q_OS_MAC } -void MainWindow::createBitField() { - m_widgets.bitField = new BitFieldWidget(m_widgets.root); - m_layouts.root->addWidget(m_widgets.bitField); - m_widgets.bitField->show(); - m_widgets.display->scrollToBottom(); - connect(m_widgets.bitField, SIGNAL(bitsChanged(const QString&)), SLOT(handleBitsChanged(const QString&))); - m_settings->bitfieldVisible = true; +void MainWindow::createBitFieldDock() { + m_docks.bitField = new BitFieldDock(this); + m_docks.bitField->setObjectName("BitFieldDock"); + m_docks.bitField->installEventFilter(this); + m_docks.bitField->setAllowedAreas(Qt::AllDockWidgetAreas); + //m_docks.bitField->setFeatures(m_docks.bitField->features() | QDockWidget::DockWidgetVerticalTitleBar); + addDockWidget(Qt::BottomDockWidgetArea, m_docks.bitField); + + connect(m_docks.bitField->widget(), SIGNAL(bitsChanged(const QString&)), SLOT(handleBitsChanged(const QString&))); + + m_docks.bitField->show(); + m_docks.bitField->raise(); + + m_settings->bitFieldDockVisible = true; } void MainWindow::createBookDock() @@ -889,7 +896,7 @@ void MainWindow::createFixedConnections() #endif connect(m_actions.viewStatusBar, SIGNAL(toggled(bool)), SLOT(setStatusBarVisible(bool))); connect(m_actions.viewVariables, SIGNAL(toggled(bool)), SLOT(setVariablesDockVisible(bool))); - connect(m_actions.viewBitfield, SIGNAL(toggled(bool)), SLOT(setBitfieldVisible(bool))); + connect(m_actions.viewBitfield, SIGNAL(toggled(bool)), SLOT(setBitfieldDockVisible(bool))); connect(m_actions.viewUserFunctions, SIGNAL(toggled(bool)), SLOT(setUserFunctionsDockVisible(bool))); connect(m_actions.settingsAngleUnitDegree, SIGNAL(triggered()), SLOT(setAngleModeDegree())); @@ -988,7 +995,7 @@ void MainWindow::applySettings() m_actions.viewFunctions->setChecked(m_settings->functionsDockVisible); m_actions.viewHistory->setChecked(m_settings->historyDockVisible); m_actions.viewVariables->setChecked(m_settings->variablesDockVisible); - m_actions.viewBitfield->setChecked(m_settings->bitfieldVisible); + m_actions.viewBitfield->setChecked(m_settings->bitFieldDockVisible); m_actions.viewUserFunctions->setChecked(m_settings->userFunctionsDockVisible); resize(m_settings->windowSize); @@ -1232,6 +1239,8 @@ MainWindow::~MainWindow() { if (m_widgets.trayIcon) m_widgets.trayIcon->hide(); + if (m_docks.bitField) + deleteBitFieldDock(); if (m_docks.book) deleteBookDock(); if (m_docks.constants) @@ -1669,12 +1678,12 @@ void MainWindow::setAutoCompletionEnabled(bool b) m_widgets.editor->setAutoCompletionEnabled(b); } -void MainWindow::setBitfieldVisible(bool b) +void MainWindow::setBitfieldDockVisible(bool b) { if (b) - createBitField(); + createBitFieldDock(); else - deleteBitField(); + deleteBitFieldDock(); } void MainWindow::setSystemTrayIconEnabled(bool b) @@ -1951,6 +1960,14 @@ void MainWindow::setFullScreenEnabled(bool b) bool MainWindow::eventFilter(QObject* o, QEvent* e) { + if (o == m_docks.bitField) { + if (e->type() == QEvent::Close) { + deleteBitFieldDock(); + return true; + } + return false; + } + if (o == m_docks.book) { if (e->type() == QEvent::Close) { deleteBookDock(); @@ -2013,14 +2030,18 @@ void MainWindow::deleteStatusBar() setStatusBar(0); } -void MainWindow::deleteBitField() +void MainWindow::deleteBitFieldDock() { - m_widgets.bitField->hide(); - m_layouts.root->removeWidget(m_widgets.bitField); - disconnect(m_widgets.bitField); - m_widgets.bitField->deleteLater(); - m_widgets.bitField = 0; - m_settings->bitfieldVisible = false; + Q_ASSERT(m_docks.bitField); + + removeDockWidget(m_docks.bitField); + disconnect(m_docks.bitField); + m_docks.bitField->deleteLater(); + m_docks.bitField = 0; + m_actions.viewBitfield->blockSignals(true); + m_actions.viewBitfield->setChecked(false); + m_actions.viewBitfield->blockSignals(false); + m_settings->bitFieldDockVisible = false; } void MainWindow::deleteBookDock() @@ -2421,8 +2442,8 @@ void MainWindow::evaluateEditorExpression() m_widgets.editor->setAnsAvailable(true); } - if (m_settings->bitfieldVisible) - m_widgets.bitField->updateBits(result); + if (m_settings->bitFieldDockVisible) + m_docks.bitField->updateBits(result); if (m_settings->variablesDockVisible) m_docks.variables->updateList(); diff --git a/src/gui/mainwindow.h b/src/gui/mainwindow.h index 2ba1d512..1f88479b 100644 --- a/src/gui/mainwindow.h +++ b/src/gui/mainwindow.h @@ -25,7 +25,7 @@ #include class AutoHideLabel; -class BitFieldWidget; +class BitFieldDock; class BookDock; class Constants; class ConstantsDock; @@ -111,7 +111,7 @@ private slots: void setAutoAnsEnabled(bool); void setAutoCalcEnabled(bool); void setAutoCompletionEnabled(bool); - void setBitfieldVisible(bool); + void setBitfieldDockVisible(bool); void setConstantsDockVisible(bool); void setFormulaBookDockVisible(bool); void setFullScreenEnabled(bool); @@ -186,7 +186,7 @@ private slots: void createMenus(); void createStatusBar(); void createFixedWidgets(); - void createBitField(); + void createBitFieldDock(); void createBookDock(); void createConstantsDock(); void createFunctionsDock(); @@ -203,7 +203,7 @@ private slots: void restoreVariables(); void restoreUserFunctions(); void deleteStatusBar(); - void deleteBitField(); + void deleteBitFieldDock(); void deleteBookDock(); void deleteConstantsDock(); void deleteFunctionsDock(); @@ -342,10 +342,10 @@ private slots: TipWidget* tip; QSystemTrayIcon* trayIcon; ManualWindow* manual; - BitFieldWidget* bitField; } m_widgets; struct { + BitFieldDock* bitField; BookDock* book; ConstantsDock* constants; FunctionsDock* functions; diff --git a/src/speedcrunch.pro b/src/speedcrunch.pro index 2a125286..e9ea56ae 100644 --- a/src/speedcrunch.pro +++ b/src/speedcrunch.pro @@ -54,6 +54,7 @@ HEADERS += core/book.h \ core/functions.h \ core/manual.h \ gui/aboutbox.h \ + gui/bitfielddock.h \ gui/bitfieldwidget.h \ gui/bookdock.h \ gui/constantsdock.h \ @@ -82,6 +83,7 @@ SOURCES += main.cpp \ core/pageserver.cpp \ core/settings.cpp \ gui/aboutbox.cpp \ + gui/bitfielddock.cpp \ gui/bitfieldwidget.cpp \ gui/bookdock.cpp \ gui/constantsdock.cpp \ From 322136375804fb9e6f63830fc6af8365e9dbeb50 Mon Sep 17 00:00:00 2001 From: Richard Pecl Date: Wed, 19 Nov 2014 00:23:04 +0100 Subject: [PATCH 2/4] bitfield dock's title bar can be hidden with menu checkbox --- src/core/settings.cpp | 6 ++++-- src/core/settings.h | 1 + src/gui/bitfielddock.cpp | 8 ++++++++ src/gui/bitfielddock.h | 1 + src/gui/bitfieldwidget.cpp | 33 +++++++++++++-------------------- src/gui/mainwindow.cpp | 21 ++++++++++++++++++++- src/gui/mainwindow.h | 2 ++ 7 files changed, 49 insertions(+), 23 deletions(-) diff --git a/src/core/settings.cpp b/src/core/settings.cpp index 794cfcf4..0a6be206 100644 --- a/src/core/settings.cpp +++ b/src/core/settings.cpp @@ -120,7 +120,8 @@ void Settings::load() userFunctionsDockVisible = settings->value(key + QLatin1String("UserFunctionsDockVisible"), false).toBool(); formulaBookDockVisible = settings->value(key + QLatin1String("FormulaBookDockVisible"), false).toBool(); constantsDockVisible = settings->value(key + QLatin1String("ConstantsDockVisible"), false).toBool(); - bitFieldDockVisible = settings->value(key + QLatin1String("bitFieldDockVisible"), false).toBool(); + bitFieldDockVisible = settings->value(key + QLatin1String("BitFieldDockVisible"), false).toBool(); + bitFieldDockTitle = settings->value(key + QLatin1String("BitFieldDockTitle"), true).toBool(); windowAlwaysOnTop = settings->value(key + QLatin1String("WindowAlwaysOnTop"), false).toBool(); windowPosition = settings->value(key + QLatin1String("WindowPosition"), QPoint()).toPoint(); @@ -263,7 +264,8 @@ void Settings::save() settings->setValue(key + QLatin1String("StatusBarVisible"), statusBarVisible); settings->setValue(key + QLatin1String("VariablesDockVisible"), variablesDockVisible); settings->setValue(key + QLatin1String("UserFunctionsDockVisible"), userFunctionsDockVisible); - settings->setValue(key + QLatin1String("bitFieldDockVisible"), bitFieldDockVisible); + settings->setValue(key + QLatin1String("BitFieldDockVisible"), bitFieldDockVisible); + settings->setValue(key + QLatin1String("BitFieldDockTitle"), bitFieldDockTitle); settings->setValue(key + QLatin1String("WindowPosition"), windowPosition); settings->setValue(key + QLatin1String("WindowSize"), windowSize); settings->setValue(key + QLatin1String("WindowAlwaysOnTop"), windowAlwaysOnTop); diff --git a/src/core/settings.h b/src/core/settings.h index ed1a48bd..0fad2902 100644 --- a/src/core/settings.h +++ b/src/core/settings.h @@ -68,6 +68,7 @@ class Settings { bool variablesDockVisible; bool userFunctionsDockVisible; bool bitFieldDockVisible; + bool bitFieldDockTitle; bool windowOnfullScreen; int colorScheme; diff --git a/src/gui/bitfielddock.cpp b/src/gui/bitfielddock.cpp index b499bd45..711bd0a1 100644 --- a/src/gui/bitfielddock.cpp +++ b/src/gui/bitfielddock.cpp @@ -32,6 +32,14 @@ BitFieldDock::BitFieldDock(QWidget *parent) retranslateText(); } +void BitFieldDock::displayTitleBar(bool on) +{ + if (on) + setTitleBarWidget(NULL); + else + setTitleBarWidget(new QWidget()); +} + void BitFieldDock::updateBits(const HNumber& number) { m_widget->updateBits(number); diff --git a/src/gui/bitfielddock.h b/src/gui/bitfielddock.h index f8bf46aa..4b32db03 100644 --- a/src/gui/bitfielddock.h +++ b/src/gui/bitfielddock.h @@ -33,6 +33,7 @@ class BitFieldDock : public QDockWidget BitFieldDock(QWidget *parent = 0); public slots: + void displayTitleBar(bool); void updateBits(const HNumber&); protected: diff --git a/src/gui/bitfieldwidget.cpp b/src/gui/bitfieldwidget.cpp index aa98bdaa..84f5da22 100644 --- a/src/gui/bitfieldwidget.cpp +++ b/src/gui/bitfieldwidget.cpp @@ -82,6 +82,9 @@ BitFieldWidget::BitFieldWidget(QWidget* parent) : QGridLayout* fieldLayout = new QGridLayout; int bitOffset = 0; + // add empty row so that there will be the same row-spacing maring at top and bottom + fieldLayout->addWidget(new QWidget(), 0, 0, -1, -1); + for (int column = 0; column < 17; ++column) { if ((column % 2) == 0) { if ((column % 4) != 0) @@ -101,8 +104,8 @@ BitFieldWidget::BitFieldWidget(QWidget* parent) : topNumberLabel->setText(QString("%1").arg(topNumber)); bottomNumberLabel->setText(QString("%1").arg(bottomNumber)); - fieldLayout->addWidget(topNumberLabel, 0, column); - fieldLayout->addWidget(bottomNumberLabel, 1, column); + fieldLayout->addWidget(topNumberLabel, 1, column); + fieldLayout->addWidget(bottomNumberLabel, 2, column); } else { QHBoxLayout* bottomLayout(new QHBoxLayout); @@ -116,8 +119,8 @@ BitFieldWidget::BitFieldWidget(QWidget* parent) : ++bitOffset; - fieldLayout->addLayout(bottomLayout, 1, column, Qt::AlignCenter); - fieldLayout->addLayout(topLayout, 0, column, Qt::AlignCenter); + fieldLayout->addLayout(bottomLayout, 2, column, Qt::AlignCenter); + fieldLayout->addLayout(topLayout, 1, column, Qt::AlignCenter); } } @@ -142,29 +145,19 @@ BitFieldWidget::BitFieldWidget(QWidget* parent) : connect(shiftRightButton, SIGNAL(clicked()), this, SLOT(shiftBitsRight())); int col = fieldLayout->columnCount(); - fieldLayout->addWidget(resetButton, 0, col); - fieldLayout->addWidget(shiftLeftButton, 1, col); - fieldLayout->addWidget(invertButton, 0, ++col); - fieldLayout->addWidget(shiftRightButton, 1, col); + fieldLayout->addWidget(resetButton, 1, col); + fieldLayout->addWidget(shiftLeftButton, 2, col); + fieldLayout->addWidget(invertButton, 1, ++col); + fieldLayout->addWidget(shiftRightButton, 2, col); // add empty row eating as much as possible (no spacing between format rows) - fieldLayout->addWidget(new QWidget(), 2, 0, -1, -1); - fieldLayout->setRowStretch(2, 1); + fieldLayout->addWidget(new QWidget(), 3, 0, -1, -1); + fieldLayout->setRowStretch(3, 1); - //QVBoxLayout* buttonsLayout = new QVBoxLayout; - //buttonsLayout->addWidget(resetButton); - //buttonsLayout->addWidget(shiftLeftButton); - - //QVBoxLayout* buttonsLayout2 = new QVBoxLayout; - //buttonsLayout2->addWidget(invertButton); - //buttonsLayout2->addWidget(shiftRightButton); - QHBoxLayout* mainLayout = new QHBoxLayout(this); mainLayout->setMargin(0); mainLayout->addStretch(); mainLayout->addLayout(fieldLayout); - //mainLayout->addLayout(buttonsLayout); - //mainLayout->addLayout(buttonsLayout2); mainLayout->addStretch(); } diff --git a/src/gui/mainwindow.cpp b/src/gui/mainwindow.cpp index 60e0fd1c..cb4b2379 100644 --- a/src/gui/mainwindow.cpp +++ b/src/gui/mainwindow.cpp @@ -132,6 +132,8 @@ void MainWindow::createActions() m_actions.viewStatusBar = new QAction(this); m_actions.viewVariables = new QAction(this); m_actions.viewBitfield = new QAction(this); + m_actions.viewBitfieldDockTitle = new QAction(this); + m_actions.viewBitfieldDockTitle->setEnabled(false); m_actions.viewUserFunctions = new QAction(this); m_actions.settingsAngleUnitDegree = new QAction(this); m_actions.settingsAngleUnitRadian = new QAction(this); @@ -236,6 +238,7 @@ void MainWindow::createActions() m_actions.viewStatusBar->setCheckable(true); m_actions.viewVariables->setCheckable(true); m_actions.viewBitfield->setCheckable(true); + m_actions.viewBitfieldDockTitle->setCheckable(true); m_actions.viewUserFunctions->setCheckable(true); m_actions.settingsDisplayColorSchemeStandard->setData(SyntaxHighlighter::Standard); @@ -332,6 +335,7 @@ void MainWindow::setActionsText() m_actions.viewStatusBar->setText(MainWindow::tr("&Status Bar")); m_actions.viewVariables->setText(MainWindow::tr("&Variables")); m_actions.viewBitfield->setText(MainWindow::tr("Bitfield")); + m_actions.viewBitfieldDockTitle->setText(MainWindow::tr("Bitfield dock title bar")); m_actions.viewUserFunctions->setText(MainWindow::tr("Use&r Functions")); m_actions.settingsAngleUnitDegree->setText(MainWindow::tr("&Degree")); @@ -494,6 +498,8 @@ void MainWindow::createMenus() m_menus.view->addAction(m_actions.viewBitfield); m_menus.view->addAction(m_actions.viewHistory); m_menus.view->addSeparator(); + m_menus.view->addAction(m_actions.viewBitfieldDockTitle); + m_menus.view->addSeparator(); m_menus.view->addAction(m_actions.viewStatusBar); #ifndef Q_OS_MAC if (shouldAllowHiddenMenuBar()) @@ -681,13 +687,14 @@ void MainWindow::createBitFieldDock() { m_docks.bitField->setObjectName("BitFieldDock"); m_docks.bitField->installEventFilter(this); m_docks.bitField->setAllowedAreas(Qt::AllDockWidgetAreas); - //m_docks.bitField->setFeatures(m_docks.bitField->features() | QDockWidget::DockWidgetVerticalTitleBar); + m_docks.bitField->displayTitleBar(m_settings->bitFieldDockTitle); addDockWidget(Qt::BottomDockWidgetArea, m_docks.bitField); connect(m_docks.bitField->widget(), SIGNAL(bitsChanged(const QString&)), SLOT(handleBitsChanged(const QString&))); m_docks.bitField->show(); m_docks.bitField->raise(); + m_actions.viewBitfieldDockTitle->setEnabled(true); m_settings->bitFieldDockVisible = true; } @@ -897,6 +904,7 @@ void MainWindow::createFixedConnections() connect(m_actions.viewStatusBar, SIGNAL(toggled(bool)), SLOT(setStatusBarVisible(bool))); connect(m_actions.viewVariables, SIGNAL(toggled(bool)), SLOT(setVariablesDockVisible(bool))); connect(m_actions.viewBitfield, SIGNAL(toggled(bool)), SLOT(setBitfieldDockVisible(bool))); + connect(m_actions.viewBitfieldDockTitle, SIGNAL(toggled(bool)), SLOT(setBitfieldDockTitle(bool))); connect(m_actions.viewUserFunctions, SIGNAL(toggled(bool)), SLOT(setUserFunctionsDockVisible(bool))); connect(m_actions.settingsAngleUnitDegree, SIGNAL(triggered()), SLOT(setAngleModeDegree())); @@ -996,6 +1004,8 @@ void MainWindow::applySettings() m_actions.viewHistory->setChecked(m_settings->historyDockVisible); m_actions.viewVariables->setChecked(m_settings->variablesDockVisible); m_actions.viewBitfield->setChecked(m_settings->bitFieldDockVisible); + m_actions.viewBitfieldDockTitle->setChecked(m_settings->bitFieldDockTitle); + setBitfieldDockTitle(m_settings->bitFieldDockTitle); m_actions.viewUserFunctions->setChecked(m_settings->userFunctionsDockVisible); resize(m_settings->windowSize); @@ -1218,6 +1228,7 @@ MainWindow::MainWindow() m_conditions.notifyMenuBarHidden = true; #endif + m_docks.bitField = 0; m_docks.book = 0; m_docks.history = 0; m_docks.constants = 0; @@ -1686,6 +1697,13 @@ void MainWindow::setBitfieldDockVisible(bool b) deleteBitFieldDock(); } +void MainWindow::setBitfieldDockTitle(bool on) +{ + if (m_docks.bitField) + m_docks.bitField->displayTitleBar(on); + m_settings->bitFieldDockTitle = on; +} + void MainWindow::setSystemTrayIconEnabled(bool b) { if (b && !m_widgets.trayIcon && QSystemTrayIcon::isSystemTrayAvailable()) { @@ -2041,6 +2059,7 @@ void MainWindow::deleteBitFieldDock() m_actions.viewBitfield->blockSignals(true); m_actions.viewBitfield->setChecked(false); m_actions.viewBitfield->blockSignals(false); + m_actions.viewBitfieldDockTitle->setEnabled(false); m_settings->bitFieldDockVisible = false; } diff --git a/src/gui/mainwindow.h b/src/gui/mainwindow.h index 1f88479b..d1bcf012 100644 --- a/src/gui/mainwindow.h +++ b/src/gui/mainwindow.h @@ -112,6 +112,7 @@ private slots: void setAutoCalcEnabled(bool); void setAutoCompletionEnabled(bool); void setBitfieldDockVisible(bool); + void setBitfieldDockTitle(bool); void setConstantsDockVisible(bool); void setFormulaBookDockVisible(bool); void setFullScreenEnabled(bool); @@ -250,6 +251,7 @@ private slots: QAction* viewStatusBar; QAction* viewFullScreenMode; QAction* viewBitfield; + QAction* viewBitfieldDockTitle; QAction* settingsResultFormatGeneral; QAction* settingsResultFormatFixed; QAction* settingsResultFormatEngineering; From 3202307658856fbe89c6e1531eb1c2a5cd71e4ce Mon Sep 17 00:00:00 2001 From: Richard Pecl Date: Thu, 20 Nov 2014 11:21:51 +0100 Subject: [PATCH 3/4] increased left&right margin around bitfiled widget --- src/gui/bitfieldwidget.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/gui/bitfieldwidget.cpp b/src/gui/bitfieldwidget.cpp index 84f5da22..c0cf0f93 100644 --- a/src/gui/bitfieldwidget.cpp +++ b/src/gui/bitfieldwidget.cpp @@ -29,7 +29,7 @@ #include #include -//------------------------------------------------------------------------------ +//------------------------------------------------------------------------------ BitWidget::BitWidget(int bitPosition, QWidget* parent) : QLabel(parent), @@ -38,7 +38,7 @@ BitWidget::BitWidget(int bitPosition, QWidget* parent) setMinimumSize(SizePixels, SizePixels); setMaximumSize(SizePixels*4, SizePixels*4); setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Minimum); - + HNumber number(HMath::raise(HNumber(2), bitPosition)); setToolTip(QString("2%1 = %2") .arg(bitPosition) @@ -67,7 +67,7 @@ void BitWidget::paintEvent(QPaintEvent* event) painter.drawRect(event->rect()); } -//------------------------------------------------------------------------------ +//------------------------------------------------------------------------------ BitFieldWidget::BitFieldWidget(QWidget* parent) : QWidget(parent) @@ -153,9 +153,9 @@ BitFieldWidget::BitFieldWidget(QWidget* parent) : // add empty row eating as much as possible (no spacing between format rows) fieldLayout->addWidget(new QWidget(), 3, 0, -1, -1); fieldLayout->setRowStretch(3, 1); - + QHBoxLayout* mainLayout = new QHBoxLayout(this); - mainLayout->setMargin(0); + mainLayout->setContentsMargins(2, 0, 2, 0); mainLayout->addStretch(); mainLayout->addLayout(fieldLayout); mainLayout->addStretch(); From 8f6a0b81db82fdd2d711dc3dd91b25ade0a041fe Mon Sep 17 00:00:00 2001 From: Richard Pecl Date: Thu, 20 Nov 2014 11:55:22 +0100 Subject: [PATCH 4/4] state label position is updated on editor position change --- src/gui/editor.cpp | 5 +++++ src/gui/editor.h | 3 +++ src/gui/mainwindow.cpp | 8 +++++++- src/gui/mainwindow.h | 1 + 4 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/gui/editor.cpp b/src/gui/editor.cpp index 6ec2cf9b..399561c0 100644 --- a/src/gui/editor.cpp +++ b/src/gui/editor.cpp @@ -778,6 +778,11 @@ void Editor::keyPressEvent(QKeyEvent* event) QPlainTextEdit::keyPressEvent(event); } +void Editor::moveEvent(QMoveEvent* event) +{ + emit posChanged(event); +} + void Editor::wheelEvent(QWheelEvent* event) { if (event->delta() > 0) diff --git a/src/gui/editor.h b/src/gui/editor.h index 8adf5de9..74dfbafd 100644 --- a/src/gui/editor.h +++ b/src/gui/editor.h @@ -32,6 +32,7 @@ class SyntaxHighlighter; class QEvent; class QKeyEvent; class QMimeData; +class QMoveEvent; class QTimeLine; class QTreeWidget; class QWheelEvent; @@ -71,6 +72,7 @@ class Editor : public QPlainTextEdit { void copySequencePressed(); void pageDownPressed(); void pageUpPressed(); + void posChanged(const QMoveEvent* event); void returnPressed(); void shiftDownPressed(); void shiftUpPressed(); @@ -109,6 +111,7 @@ protected slots: virtual void changeEvent(QEvent*); virtual void focusOutEvent(QFocusEvent*); virtual void keyPressEvent(QKeyEvent*); + virtual void moveEvent(QMoveEvent*); virtual void paintEvent(QPaintEvent*); virtual void wheelEvent(QWheelEvent*); diff --git a/src/gui/mainwindow.cpp b/src/gui/mainwindow.cpp index cb4b2379..1b73e1b2 100644 --- a/src/gui/mainwindow.cpp +++ b/src/gui/mainwindow.cpp @@ -691,7 +691,7 @@ void MainWindow::createBitFieldDock() { addDockWidget(Qt::BottomDockWidgetArea, m_docks.bitField); connect(m_docks.bitField->widget(), SIGNAL(bitsChanged(const QString&)), SLOT(handleBitsChanged(const QString&))); - + m_docks.bitField->show(); m_docks.bitField->raise(); m_actions.viewBitfieldDockTitle->setEnabled(true); @@ -955,6 +955,7 @@ void MainWindow::createFixedConnections() connect(m_widgets.editor, SIGNAL(autoCalcDisabled()), SLOT(hideStateLabel())); connect(m_widgets.editor, SIGNAL(autoCalcEnabled(const QString&)), SLOT(showStateLabel(const QString&))); + connect(m_widgets.editor, SIGNAL(posChanged(const QMoveEvent*)), SLOT(updateStateLabelPos())); connect(m_widgets.editor, SIGNAL(returnPressed()), SLOT(evaluateEditorExpression())); connect(m_widgets.editor, SIGNAL(shiftDownPressed()), SLOT(decreaseDisplayFontPointSize())); connect(m_widgets.editor, SIGNAL(shiftUpPressed()), SLOT(increaseDisplayFontPointSize())); @@ -1965,6 +1966,11 @@ void MainWindow::showStateLabel(const QString& msg) m_widgets.state->adjustSize(); m_widgets.state->show(); m_widgets.state->raise(); + updateStateLabelPos(); +} + +void MainWindow::updateStateLabelPos() +{ const int height = m_widgets.state->height(); QPoint pos = mapFromGlobal(m_widgets.editor->mapToGlobal(QPoint(0, -height))); m_widgets.state->move(pos); diff --git a/src/gui/mainwindow.h b/src/gui/mainwindow.h index d1bcf012..2d0d6b8a 100644 --- a/src/gui/mainwindow.h +++ b/src/gui/mainwindow.h @@ -170,6 +170,7 @@ private slots: void showSystemTrayMessage(); void increaseDisplayFontPointSize(); void decreaseDisplayFontPointSize(); + void updateStateLabelPos(); protected: virtual void closeEvent(QCloseEvent*);