Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

ui_qt: use fixed char width

  • Loading branch information...
commit 0ab52d212646ff94d221245c5eb7ef47517810ee 1 parent 584b473
@wisk authored
View
25 src/ui/qt/DisassemblyView.cpp
@@ -14,8 +14,7 @@ DisassemblyView::DisassemblyView(QWidget * parent)
, _cursorTimer(), _cursorBlink(false)
, _visibleLines()
{
- setFont(QFont("consolas", 10));
-
+ setFont();
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
connect(&_cursorTimer, SIGNAL(timeout()), this, SLOT(updateCursor()));
@@ -42,8 +41,11 @@ bool DisassemblyView::goTo(medusa::Database::View::LineInformation const & lineI
return true;
}
-void DisassemblyView::setFont(QFont const & font)
+void DisassemblyView::setFont(void)
{
+ QString fontInfo = Settings::instance().value(MEDUSA_FONT_TEXT, MEDUSA_FONT_TEXT_DEFAULT).toString();
+ QFont font;
+ font.fromString(fontInfo);
QAbstractScrollArea::setFont(font);
const QFontMetrics metrics(font);
@@ -84,6 +86,15 @@ void DisassemblyView::paintEvent(QPaintEvent * evt)
{
QPainter p(viewport());
+ auto drawText = [this](QPainter & p, int x, int y, QString const & text)
+ {
+ foreach (QChar chr, text)
+ {
+ p.drawText(x, y, chr);
+ x += this->_wChar;
+ }
+ };
+
// Draw background
QColor addrColor = QColor(Settings::instance().value(MEDUSA_COLOR_ADDRESS_BACKGROUND, MEDUSA_COLOR_ADDRESS_BACKGROUND_DEFAULT).toString());
QColor codeColor = QColor(Settings::instance().value(MEDUSA_COLOR_VIEW_BACKGROUND, MEDUSA_COLOR_VIEW_BACKGROUND_DEFAULT).toString());
@@ -181,7 +192,7 @@ void DisassemblyView::paintEvent(QPaintEvent * evt)
// Draw address lines
for (int line = 0; line < endLine && _db->GetView().GetLineInformation(line + curLine, lineInfo); ++line)
{
- p.drawText(begLine, _yOffset + line * _hChar, QString::fromStdString(lineInfo.GetAddress().ToString()));
+ drawText(p, begLine, _yOffset + line * _hChar, QString::fromStdString(lineInfo.GetAddress().ToString()));
}
// Draw assembly code lines
@@ -224,7 +235,7 @@ void DisassemblyView::paintEvent(QPaintEvent * evt)
};
p.setPen(cellClr);
- p.drawText(begLine + offset * _wChar + offLine, _yOffset + line * _hChar, cellStr);
+ drawText(p, begLine + offset * _wChar + offLine, _yOffset + line * _hChar, cellStr);
offset += mark.GetLength();
});
@@ -233,7 +244,7 @@ void DisassemblyView::paintEvent(QPaintEvent * evt)
if (!curCell->GetComment().empty())
{
p.setPen(QColor(Settings::instance().value(MEDUSA_COLOR_INSTRUCTION_COMMENT, MEDUSA_COLOR_INSTRUCTION_COMMENT_DEFAULT).toString()));
- p.drawText(begLine + offset * _wChar + offLine, _yOffset + line * _hChar, QString(" ; ") + QString::fromStdString(curCell->GetComment()));
+ drawText(p, begLine + offset * _wChar + offLine, _yOffset + line * _hChar, QString(" ; ") + QString::fromStdString(curCell->GetComment()));
visibleLine += QString(" %1 ").arg(QString::fromStdString(curCell->GetComment()));
}
break;
@@ -295,7 +306,7 @@ void DisassemblyView::paintEvent(QPaintEvent * evt)
if (lineStr.isEmpty()) continue;
p.setPen(color);
- p.drawText(begLine + offLine, _yOffset + line * _hChar, lineStr);
+ drawText(p, begLine + offLine, _yOffset + line * _hChar, lineStr);
}
// Draw cursor
View
2  src/ui/qt/DisassemblyView.hpp
@@ -30,7 +30,7 @@ class DisassemblyView : public QAbstractScrollArea
signals:
public slots:
- void setFont(QFont const & font);
+ void setFont(void);
void listingUpdated(void);
void updateCursor(void);
void showContextMenu(QPoint const& pos);
View
12 src/ui/qt/MainWindow.cpp
@@ -49,6 +49,7 @@ MainWindow::MainWindow()
connect(this, SIGNAL(logAppended(wchar_t const*)), this, SLOT(onLogMessageAppended(wchar_t const *)));
connect(this, SIGNAL(disassemblyListingUpdated()), &_disasmView, SLOT(listingUpdated()));
+ connect(&Settings::instance(), SIGNAL(settingsChanged()), &_disasmView, SLOT(setFont()));
qRegisterMetaType<medusa::Label>("medusa::Label");
connect(this, SIGNAL(labelAdded(medusa::Label const&)), this, SLOT(onLabelAdded(medusa::Label const&)));
@@ -229,18 +230,7 @@ void MainWindow::onLabelAdded(medusa::Label const & label)
void MainWindow::closeEvent(QCloseEvent * event)
{
- // if a document is currently opened
- //if (this->_documentOpened)
- //{
- // // Close it, but prevent window from closing while unloading
- // if (this->closeDocument())
- // this->_closeWindow = true;
- // event->ignore();
- //}
- //else
- //{
Settings::instance().setValue(WINDOW_LAYOUT, this->saveState());
Settings::instance().setValue(WINDOW_GEOMETRY, this->saveGeometry());
event->accept();
- //}
}
View
10 src/ui/qt/Settings.hpp
@@ -25,10 +25,7 @@
# define MEDUSA_COLOR_ADDRESS_BACKGROUND "settings/listing/address/background"
// Font
-# define MEDUSA_FONT_MNEMONIC "settings/listing/font/mnemonic"
-# define MEDUSA_FONT_REGISTER "settings/listing/font/register"
-# define MEDUSA_FONT_IMMEDIATE "settings/listing/font/immediate"
-# define MEDUSA_FONT_COMMENT "settings/listing/font/comment"
+# define MEDUSA_FONT_TEXT "settings/listing/font/text"
/***********************
* Default
@@ -52,10 +49,7 @@
# define MEDUSA_COLOR_ADDRESS_BACKGROUND_DEFAULT "#333333"
// Font
-# define MEDUSA_FONT_MNEMONIC_DEFAULT "Arial,10,-1,5,50,0,0,0,0,0"
-# define MEDUSA_FONT_REGISTER_DEFAULT "Arial,10,-1,5,50,0,0,0,0,0"
-# define MEDUSA_FONT_IMMEDIATE_DEFAULT "Arial,10,-1,5,50,0,0,0,0,0"
-# define MEDUSA_FONT_COMMENT_DEFAULT "Arial,10,-1,5,50,0,0,0,0,0"
+# define MEDUSA_FONT_TEXT_DEFAULT "Consolas,10,-1,5,50,0,0,0,0,0"
class Settings : public QSettings
{
View
15 src/ui/qt/SettingsDialog.cpp
@@ -34,14 +34,8 @@ void SettingsDialog::showEvent(QShowEvent * e)
// Font
QFont font;
- font.fromString(Settings::instance().value(MEDUSA_FONT_MNEMONIC, MEDUSA_FONT_MNEMONIC_DEFAULT).toString());
- this->mnemonicFont->setFont(font);
- font.fromString(Settings::instance().value(MEDUSA_FONT_REGISTER, MEDUSA_FONT_REGISTER_DEFAULT).toString());
- this->registerFont->setFont(font);
- font.fromString(Settings::instance().value(MEDUSA_FONT_IMMEDIATE, MEDUSA_FONT_IMMEDIATE_DEFAULT).toString());
- this->mnemonicFont->setFont(font);
- font.fromString(Settings::instance().value(MEDUSA_FONT_COMMENT, MEDUSA_FONT_COMMENT_DEFAULT).toString());
- this->commentFont->setFont(font);
+ font.fromString(Settings::instance().value(MEDUSA_FONT_TEXT, MEDUSA_FONT_TEXT_DEFAULT).toString());
+ this->textFont->setFont(font);
}
void SettingsDialog::saveSettings()
@@ -60,10 +54,7 @@ void SettingsDialog::saveSettings()
Settings::instance().setValue(MEDUSA_COLOR_ADDRESS_BACKGROUND, this->addressBackground->color().name());
// Font
- Settings::instance().setValue(MEDUSA_FONT_MNEMONIC, this->mnemonicFont->font().toString());
- Settings::instance().setValue(MEDUSA_FONT_REGISTER, this->registerFont->font().toString());
- Settings::instance().setValue(MEDUSA_FONT_IMMEDIATE, this->immediateFont->font().toString());
- Settings::instance().setValue(MEDUSA_FONT_COMMENT, this->commentFont->font().toString());
+ Settings::instance().setValue(MEDUSA_FONT_TEXT, this->textFont->font().toString());
Settings::instance().saveChanges();
}
View
156 src/ui/qt/SettingsDialog.ui
@@ -33,7 +33,7 @@
<enum>QTabWidget::North</enum>
</property>
<property name="currentIndex">
- <number>1</number>
+ <number>0</number>
</property>
<property name="documentMode">
<bool>false</bool>
@@ -52,6 +52,60 @@
<attribute name="title">
<string>General</string>
</attribute>
+ <widget class="QGroupBox" name="textGroupBox">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>10</y>
+ <width>611</width>
+ <height>61</height>
+ </rect>
+ </property>
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="title">
+ <string>Text</string>
+ </property>
+ <property name="flat">
+ <bool>false</bool>
+ </property>
+ <property name="checkable">
+ <bool>false</bool>
+ </property>
+ <layout class="QVBoxLayout" name="verticalLayout_9">
+ <property name="sizeConstraint">
+ <enum>QLayout::SetMinimumSize</enum>
+ </property>
+ <item>
+ <layout class="QFormLayout" name="textFormLayout">
+ <property name="sizeConstraint">
+ <enum>QLayout::SetMinimumSize</enum>
+ </property>
+ <property name="fieldGrowthPolicy">
+ <enum>QFormLayout::AllNonFixedFieldsGrow</enum>
+ </property>
+ <item row="0" column="0">
+ <widget class="QLabel" name="labelFont">
+ <property name="text">
+ <string>Font</string>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="1">
+ <widget class="FontPicker" name="textFont">
+ <property name="enabled">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ </layout>
+ </widget>
</widget>
<widget class="QWidget" name="color">
<attribute name="icon">
@@ -72,7 +126,7 @@
<rect>
<x>0</x>
<y>0</y>
- <width>580</width>
+ <width>172</width>
<height>501</height>
</rect>
</property>
@@ -345,104 +399,6 @@
</item>
</layout>
</widget>
- <widget class="QWidget" name="font">
- <attribute name="icon">
- <iconset resource="MedusaRsrc.qrc">
- <normaloff>:/images/font.png</normaloff>:/images/font.png</iconset>
- </attribute>
- <attribute name="title">
- <string>Font</string>
- </attribute>
- <layout class="QVBoxLayout" name="verticalLayout_8">
- <item>
- <widget class="QGroupBox" name="groupBox_4">
- <property name="sizePolicy">
- <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
- <horstretch>0</horstretch>
- <verstretch>0</verstretch>
- </sizepolicy>
- </property>
- <property name="title">
- <string>Instruction</string>
- </property>
- <property name="flat">
- <bool>false</bool>
- </property>
- <property name="checkable">
- <bool>false</bool>
- </property>
- <layout class="QVBoxLayout" name="verticalLayout_7">
- <property name="sizeConstraint">
- <enum>QLayout::SetMinimumSize</enum>
- </property>
- <item>
- <layout class="QFormLayout" name="formLayout_4">
- <property name="sizeConstraint">
- <enum>QLayout::SetMinimumSize</enum>
- </property>
- <property name="fieldGrowthPolicy">
- <enum>QFormLayout::AllNonFixedFieldsGrow</enum>
- </property>
- <item row="0" column="0">
- <widget class="QLabel" name="mnemonicFontLabel">
- <property name="text">
- <string>Mnemonic</string>
- </property>
- </widget>
- </item>
- <item row="0" column="1">
- <widget class="FontPicker" name="mnemonicFont"/>
- </item>
- <item row="1" column="1">
- <widget class="FontPicker" name="registerFont"/>
- </item>
- <item row="2" column="0">
- <widget class="QLabel" name="immediateFontLabel">
- <property name="text">
- <string>Immediate</string>
- </property>
- </widget>
- </item>
- <item row="2" column="1">
- <widget class="FontPicker" name="immediateFont"/>
- </item>
- <item row="3" column="0">
- <widget class="QLabel" name="commentFontLabel">
- <property name="text">
- <string>Comment</string>
- </property>
- </widget>
- </item>
- <item row="3" column="1">
- <widget class="FontPicker" name="commentFont"/>
- </item>
- <item row="1" column="0">
- <widget class="QLabel" name="registerFontLabel">
- <property name="text">
- <string>Register</string>
- </property>
- </widget>
- </item>
- </layout>
- </item>
- </layout>
- </widget>
- </item>
- <item>
- <spacer name="verticalSpacer_3">
- <property name="orientation">
- <enum>Qt::Vertical</enum>
- </property>
- <property name="sizeHint" stdset="0">
- <size>
- <width>20</width>
- <height>40</height>
- </size>
- </property>
- </spacer>
- </item>
- </layout>
- </widget>
</widget>
</item>
<item>
Please sign in to comment.
Something went wrong with that request. Please try again.