1
0
Fork 0

GUI: fonts now fully customizable (resolved issue #132)

This commit is contained in:
Mr. eXoDia 2014-07-21 03:56:24 +02:00
parent 4e0803882c
commit bc3db1d2e2
14 changed files with 271 additions and 50 deletions

View File

@ -12,21 +12,8 @@ AbstractTableView::AbstractTableView(QWidget *parent) : QAbstractScrollArea(pare
data.activeButtonIndex=-1;
mHeader = data;
QFont font("Lucida Console", 8, QFont::Normal, false);
font.setFixedPitch(true);
font.setStyleHint(QFont::Monospace);
setFont(font);
backgroundColor=ConfigColor("AbstractTableViewBackgroundColor");
textColor=ConfigColor("AbstractTableViewTextColor");
separatorColor=ConfigColor("AbstractTableViewSeparatorColor");
headerTextColor=ConfigColor("AbstractTableViewHeaderTextColor");
selectionColor=ConfigColor("AbstractTableViewSelectionColor");
int wRowsHeight = QFontMetrics(this->font()).height();
wRowsHeight = (wRowsHeight * 105) / 100;
wRowsHeight = (wRowsHeight % 2) == 0 ? wRowsHeight : wRowsHeight + 1;
mRowHeight = wRowsHeight;
fontsUpdated();
colorsUpdated();
mRowCount = 0;
@ -49,6 +36,7 @@ AbstractTableView::AbstractTableView(QWidget *parent) : QAbstractScrollArea(pare
// Signals/Slots Connections
connect(verticalScrollBar(), SIGNAL(actionTriggered(int)), this, SLOT(vertSliderActionSlot(int)));
connect(Config(), SIGNAL(colorsUpdated()), this, SLOT(colorsUpdatedSlot()));
connect(Config(), SIGNAL(fontsUpdated()), this, SLOT(fontsUpdatedSlot()));
}
void AbstractTableView::colorsUpdatedSlot()
@ -65,6 +53,16 @@ void AbstractTableView::colorsUpdated()
selectionColor=ConfigColor("AbstractTableViewSelectionColor");
}
void AbstractTableView::fontsUpdatedSlot()
{
fontsUpdated();
}
void AbstractTableView::fontsUpdated()
{
setFont(ConfigFont("AbstractTableView"));
}
/************************************************************************************
Painting Stuff
************************************************************************************/
@ -837,7 +835,10 @@ int AbstractTableView::getColumnCount()
int AbstractTableView::getRowHeight()
{
return mRowHeight;
int wRowsHeight = QFontMetrics(this->font()).height();
wRowsHeight = (wRowsHeight * 105) / 100;
wRowsHeight = (wRowsHeight % 2) == 0 ? wRowsHeight : wRowsHeight + 1;
return wRowsHeight;
}
int AbstractTableView::getColumnWidth(int index)

View File

@ -19,8 +19,9 @@ public:
// Constructor
explicit AbstractTableView(QWidget *parent = 0);
//color updates
//config updates
virtual void colorsUpdated();
virtual void fontsUpdated();
// Pure Virtual Methods
virtual QString paintContent(QPainter* painter, int_t rowBase, int rowOffset, int col, int x, int y, int w, int h) = 0;
@ -87,6 +88,7 @@ signals:
public slots:
void colorsUpdatedSlot();
void fontsUpdatedSlot();
// Update/Reload/Refresh/Repaint
virtual void reloadData();
@ -138,7 +140,6 @@ private:
QList<Column_t> mColumnList;
int mRowHeight;
int_t mRowCount;

View File

@ -3,6 +3,7 @@
Disassembly::Disassembly(QWidget *parent) : AbstractTableView(parent)
{
fontsUpdated();
mMemPage = new MemoryPage(0, 0);
mInstBuffer.clear();
@ -44,6 +45,11 @@ void Disassembly::colorsUpdated()
backgroundColor=ConfigColor("DisassemblyBackgroundColor");
}
void Disassembly::fontsUpdated()
{
setFont(ConfigFont("Disassembly"));
}
/************************************************************************************
Reimplemented Functions
************************************************************************************/
@ -397,7 +403,7 @@ QString Disassembly::paintContent(QPainter* painter, int_t rowBase, int rowOffse
else
BeaTokenizer::TokenToRichText(token, &richText, 0);
int xinc = 4;
RichTextPainter::paintRichText(painter, x + loopsize, y, getColumnWidth(col) - loopsize, getRowHeight(), xinc, &richText, QFontMetrics(this->font()).width(QChar(' ')));
RichTextPainter::paintRichText(painter, x + loopsize, y, getColumnWidth(col) - loopsize, getRowHeight(), xinc, &richText, getCharWidth());
token->x = x + loopsize + xinc;
}
break;

View File

@ -17,6 +17,7 @@ class Disassembly : public AbstractTableView
public:
explicit Disassembly(QWidget *parent = 0);
void colorsUpdated();
void fontsUpdated();
// Reimplemented Functions
QString paintContent(QPainter* painter, int_t rowBase, int rowOffset, int col, int x, int y, int w, int h);

View File

@ -3,6 +3,7 @@
HexDump::HexDump(QWidget *parent) : AbstractTableView(parent)
{
fontsUpdated();
SelectionData_t data;
memset(&data, 0, sizeof(SelectionData_t));
mSelection = data;
@ -32,6 +33,11 @@ void HexDump::colorsUpdated()
reloadData();
}
void HexDump::fontsUpdated()
{
setFont(ConfigFont("HexDump"));
}
void HexDump::printDumpAt(int_t parVA, bool select)
{
int_t wBase = DbgMemFindBaseAddr(parVA, 0); //get memory base

View File

@ -83,6 +83,7 @@ public:
explicit HexDump(QWidget *parent = 0);
void colorsUpdated();
void fontsUpdated();
//QString getStringToPrint(int rowBase, int rowOffset, int col);
void mouseMoveEvent(QMouseEvent* event);

View File

@ -2,6 +2,7 @@
#include "ui_AppearanceDialog.h"
#include "Bridge.h"
#include "Configuration.h"
#include <QFontDialog>
AppearanceDialog::AppearanceDialog(QWidget *parent) : QDialog(parent), ui(new Ui::AppearanceDialog)
{
@ -568,6 +569,7 @@ void AppearanceDialog::colorInfoListInit()
void AppearanceDialog::fontInit()
{
isInit=true;
//AbstractTableView
QFont font=fontMap->find("AbstractTableView").value();
ui->fontAbstractTables->setCurrentFont(QFont(font.family()));
@ -654,99 +656,276 @@ void AppearanceDialog::fontInit()
ui->fontHexEditSize->setCurrentIndex(index);
//Application
ui->labelApplicationFont->setText(fontMap->find("Application").value().family());
isInit=false;
}
void AppearanceDialog::on_fontAbstractTables_currentFontChanged(const QFont &f)
{
QString id="AbstractTableView";
QFont font=fontMap->find(id).value();
font.setFamily(f.family());
(*fontMap)[id]=font;
if(isInit)
return;
Config()->writeFonts();
GuiUpdateAllViews();
}
void AppearanceDialog::on_fontAbstractTablesStyle_currentIndexChanged(int index)
{
QString id="AbstractTableView";
QFont font=fontMap->find(id).value();
font.setBold(false);
font.setItalic(false);
if(index==1 || index==3)
font.setBold(true);
if(index==2 || index==3)
font.setItalic(true);
(*fontMap)[id]=font;
if(isInit)
return;
Config()->writeFonts();
GuiUpdateAllViews();
}
void AppearanceDialog::on_fontAbstractTablesSize_currentIndexChanged(const QString &arg1)
{
QString id="AbstractTableView";
QFont font=fontMap->find(id).value();
font.setPointSize(arg1.toInt());
(*fontMap)[id]=font;
if(isInit)
return;
Config()->writeFonts();
GuiUpdateAllViews();
}
void AppearanceDialog::on_fontDisassembly_currentFontChanged(const QFont &f)
{
QString id="Disassembly";
QFont font=fontMap->find(id).value();
font.setFamily(f.family());
(*fontMap)[id]=font;
if(isInit)
return;
Config()->writeFonts();
GuiUpdateAllViews();
}
void AppearanceDialog::on_fontDisassemblyStyle_currentIndexChanged(int index)
{
QString id="Disassembly";
QFont font=fontMap->find(id).value();
font.setBold(false);
font.setItalic(false);
if(index==1 || index==3)
font.setBold(true);
if(index==2 || index==3)
font.setItalic(true);
(*fontMap)[id]=font;
if(isInit)
return;
Config()->writeFonts();
GuiUpdateAllViews();
}
void AppearanceDialog::on_fontDisassemblySize_currentIndexChanged(const QString &arg1)
{
QString id="Disassembly";
QFont font=fontMap->find(id).value();
font.setPointSize(arg1.toInt());
(*fontMap)[id]=font;
if(isInit)
return;
Config()->writeFonts();
GuiUpdateAllViews();
}
void AppearanceDialog::on_fontHexDump_currentFontChanged(const QFont &f)
{
QString id="HexDump";
QFont font=fontMap->find(id).value();
font.setFamily(f.family());
(*fontMap)[id]=font;
if(isInit)
return;
Config()->writeFonts();
GuiUpdateAllViews();
}
void AppearanceDialog::on_fontHexDumpStyle_currentIndexChanged(int index)
{
QString id="HexDump";
QFont font=fontMap->find(id).value();
font.setBold(false);
font.setItalic(false);
if(index==1 || index==3)
font.setBold(true);
if(index==2 || index==3)
font.setItalic(true);
(*fontMap)[id]=font;
if(isInit)
return;
Config()->writeFonts();
GuiUpdateAllViews();
}
void AppearanceDialog::on_fontHexDumpSize_currentIndexChanged(const QString &arg1)
{
QString id="HexDump";
QFont font=fontMap->find(id).value();
font.setPointSize(arg1.toInt());
(*fontMap)[id]=font;
if(isInit)
return;
Config()->writeFonts();
GuiUpdateAllViews();
}
void AppearanceDialog::on_fontStack_currentFontChanged(const QFont &f)
{
QString id="Stack";
QFont font=fontMap->find(id).value();
font.setFamily(f.family());
(*fontMap)[id]=font;
if(isInit)
return;
Config()->writeFonts();
GuiUpdateAllViews();
}
void AppearanceDialog::on_fontStackStyle_currentIndexChanged(int index)
{
QString id="Stack";
QFont font=fontMap->find(id).value();
font.setBold(false);
font.setItalic(false);
if(index==1 || index==3)
font.setBold(true);
if(index==2 || index==3)
font.setItalic(true);
(*fontMap)[id]=font;
if(isInit)
return;
Config()->writeFonts();
GuiUpdateAllViews();
}
void AppearanceDialog::on_fontStackSize_currentIndexChanged(const QString &arg1)
{
QString id="Stack";
QFont font=fontMap->find(id).value();
font.setPointSize(arg1.toInt());
(*fontMap)[id]=font;
if(isInit)
return;
Config()->writeFonts();
GuiUpdateAllViews();
}
void AppearanceDialog::on_fontRegisters_currentFontChanged(const QFont &f)
{
QString id="Registers";
QFont font=fontMap->find(id).value();
font.setFamily(f.family());
(*fontMap)[id]=font;
if(isInit)
return;
Config()->writeFonts();
GuiUpdateAllViews();
}
void AppearanceDialog::on_fontRegistersStyle_currentIndexChanged(int index)
{
QString id="Registers";
QFont font=fontMap->find(id).value();
font.setBold(false);
font.setItalic(false);
if(index==1 || index==3)
font.setBold(true);
if(index==2 || index==3)
font.setItalic(true);
(*fontMap)[id]=font;
if(isInit)
return;
Config()->writeFonts();
GuiUpdateAllViews();
}
void AppearanceDialog::on_fontRegistersSize_currentIndexChanged(const QString &arg1)
{
QString id="Registers";
QFont font=fontMap->find(id).value();
font.setPointSize(arg1.toInt());
(*fontMap)[id]=font;
if(isInit)
return;
Config()->writeFonts();
GuiUpdateAllViews();
}
void AppearanceDialog::on_fontHexEdit_currentFontChanged(const QFont &f)
{
QString id="HexEdit";
QFont font=fontMap->find(id).value();
font.setFamily(f.family());
(*fontMap)[id]=font;
if(isInit)
return;
Config()->writeFonts();
GuiUpdateAllViews();
}
void AppearanceDialog::on_fontHexEditStyle_currentIndexChanged(int index)
{
QString id="HexEdit";
QFont font=fontMap->find(id).value();
font.setBold(false);
font.setItalic(false);
if(index==1 || index==3)
font.setBold(true);
if(index==2 || index==3)
font.setItalic(true);
(*fontMap)[id]=font;
if(isInit)
return;
Config()->writeFonts();
GuiUpdateAllViews();
}
void AppearanceDialog::on_fontHexEditSize_currentIndexChanged(const QString &arg1)
{
QString id="HexEdit";
QFont font=fontMap->find(id).value();
font.setPointSize(arg1.toInt());
(*fontMap)[id]=font;
if(isInit)
return;
Config()->writeFonts();
GuiUpdateAllViews();
}
void AppearanceDialog::on_buttonApplicationFont_clicked()
{
QString id="Application";
QFontDialog fontDialog(this);
fontDialog.setCurrentFont(fontMap->find(id).value());
if(fontDialog.exec()!=QDialog::Accepted)
return;
(*fontMap)[id]=fontDialog.currentFont();
ui->labelApplicationFont->setText(fontDialog.currentFont().family());
if(isInit)
return;
Config()->writeFonts();
GuiUpdateAllViews();
}
void AppearanceDialog::on_buttonFontDefaults_clicked()
{
(*fontMap)=Config()->defaultFonts;
isInit=true;
fontInit();
isInit=false;
Config()->writeFonts();
GuiUpdateAllViews();
}

View File

@ -72,6 +72,7 @@ private slots:
void on_fontHexEditStyle_currentIndexChanged(int index);
void on_fontHexEditSize_currentIndexChanged(const QString &arg1);
void on_buttonApplicationFont_clicked();
void on_buttonFontDefaults_clicked();
private:
Ui::AppearanceDialog *ui;
@ -93,6 +94,8 @@ private:
QAction* defaultValueAction;
QAction* currentSettingAction;
bool isInit;
void colorInfoListAppend(QString propertyName, QString colorName, QString backgroundColorName);
void colorInfoListInit();
void fontInit();

View File

@ -703,6 +703,19 @@
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="buttonFontDefaults">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>&amp;Defaults</string>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="layoutWidget">

View File

@ -4,6 +4,7 @@
CPUStack::CPUStack(QWidget *parent) : HexDump(parent)
{
fontsUpdated();
setShowHeader(false);
int charwidth=getCharWidth();
ColumnDescriptor_t wColDesc;
@ -48,6 +49,11 @@ void CPUStack::colorsUpdated()
selectionColor=ConfigColor("StackSelectionColor");
}
void CPUStack::fontsUpdated()
{
setFont(ConfigFont("Stack"));
}
void CPUStack::setupContextMenu()
{
//Binary menu

View File

@ -16,6 +16,7 @@ class CPUStack : public HexDump
public:
explicit CPUStack(QWidget *parent = 0);
void colorsUpdated();
void fontsUpdated();
QString paintContent(QPainter* painter, int_t rowBase, int rowOffset, int col, int x, int y, int w, int h);
void contextMenuEvent(QContextMenuEvent* event);

View File

@ -25,6 +25,7 @@ HexEditDialog::HexEditDialog(QWidget *parent) :
//setup hex editor
mHexEdit = new QHexEdit(this);
mHexEdit->setEditFont(ConfigFont("HexEdit"));
mHexEdit->setHorizontalSpacing(6);
mHexEdit->setOverwriteMode(true);
mHexEdit->setTextColor(ConfigColor("HexEditTextColor"));

View File

@ -190,18 +190,8 @@ RegistersView::RegistersView(QWidget * parent) : QAbstractScrollArea(parent), mV
mRegisterMapping.insert(DR7,"DR7");
mRegisterPlaces.insert(DR7,Register_Position(offset+16,0, 4, sizeof(uint_t) * 2));
//set font
QFont font("Monospace", 8, QFont::Normal, false);
font.setFixedPitch(true);
font.setStyleHint(QFont::Monospace);
QAbstractScrollArea::setFont(font);
int wRowsHeight = QFontMetrics(this->font()).height();
wRowsHeight = (wRowsHeight * 105) / 100;
wRowsHeight = (wRowsHeight % 2) == 0 ? wRowsHeight : wRowsHeight + 1;
mRowHeight = wRowsHeight;
mCharWidth = QFontMetrics(this->font()).averageCharWidth();
fontsUpdatedSlot();
connect(Config(), SIGNAL(fontsUpdated()), this, SLOT(fontsUpdatedSlot()));
memset(&wRegDumpStruct, 0, sizeof(REGDUMP));
memset(&wCipRegDumpStruct, 0, sizeof(REGDUMP));
@ -237,6 +227,17 @@ RegistersView::~RegistersView()
{
}
void RegistersView::fontsUpdatedSlot()
{
setFont(ConfigFont("Registers"));
int wRowsHeight = QFontMetrics(this->font()).height();
wRowsHeight = (wRowsHeight * 105) / 100;
wRowsHeight = (wRowsHeight % 2) == 0 ? wRowsHeight : wRowsHeight + 1;
mRowHeight = wRowsHeight;
mCharWidth = QFontMetrics(this->font()).averageCharWidth();
repaint();
}
/**
* @brief retrieves the register id from given corrdinates of the viewport
* @param line

View File

@ -90,6 +90,7 @@ protected:
void displayEditDialog();
protected slots:
void fontsUpdatedSlot();
void onIncrementAction();
void onDecrementAction();
void onZeroAction();