1
0
Fork 0
forked from len0rd/rockbox

Theme Editor: Fixed some compiler warnings and a segfault. Got some basic text rendering working (only with plaintext elements, no font support yet) as well as Viewport background color support

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@27126 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Robert Bieber 2010-06-25 05:14:13 +00:00
parent 691d049177
commit 273b9d6050
9 changed files with 70 additions and 15 deletions

View file

@ -21,6 +21,9 @@
#include "rbfont.h" #include "rbfont.h"
#include <QFont>
#include <QBrush>
RBFont::RBFont(QString file): filename(file) RBFont::RBFont(QString file): filename(file)
{ {
} }
@ -28,3 +31,15 @@ RBFont::RBFont(QString file): filename(file)
RBFont::~RBFont() RBFont::~RBFont()
{ {
} }
QGraphicsSimpleTextItem* RBFont::renderText(QString text, QColor color,
QGraphicsItem *parent)
{
QGraphicsSimpleTextItem* retval = new QGraphicsSimpleTextItem(text, parent);
QFont font;
font.setFixedPitch(true);
font.setPixelSize(8);
retval->setFont(font);
retval->setBrush(QBrush(color));
return retval;
}

View file

@ -24,6 +24,7 @@
#include <QString> #include <QString>
#include <QFile> #include <QFile>
#include <QGraphicsSimpleTextItem>
class RBFont class RBFont
{ {
@ -31,6 +32,10 @@ public:
RBFont(QString file); RBFont(QString file);
virtual ~RBFont(); virtual ~RBFont();
QGraphicsSimpleTextItem* renderText(QString text, QColor color,
QGraphicsItem* parent = 0);
int lineHeight(){ return 8; }
private: private:
QString filename; QString filename;
}; };

View file

@ -32,10 +32,10 @@ RBScreen::RBScreen(const RBRenderInfo& info, QGraphicsItem *parent) :
width = info.settings()->value("#screenwidth", "300").toInt(); width = info.settings()->value("#screenwidth", "300").toInt();
height = info.settings()->value("#screenheight", "200").toInt(); height = info.settings()->value("#screenheight", "200").toInt();
QString bg = info.settings()->value("background color", "000000"); QString bg = info.settings()->value("background color", "FFFFFF");
bgColor = stringToColor(bg, Qt::white); bgColor = stringToColor(bg, Qt::white);
QString fg = info.settings()->value("foreground color", "FFFFFF"); QString fg = info.settings()->value("foreground color", "000000");
fgColor = stringToColor(fg, Qt::black); fgColor = stringToColor(fg, Qt::black);
settings = info.settings(); settings = info.settings();
@ -61,6 +61,8 @@ RBScreen::RBScreen(const RBRenderInfo& info, QGraphicsItem *parent) :
backdrop = 0; backdrop = 0;
} }
} }
fonts.insert(0, new RBFont("Nothin'"));
} }
RBScreen::~RBScreen() RBScreen::~RBScreen()

View file

@ -60,10 +60,14 @@ public:
RBFont* getFont(int id); RBFont* getFont(int id);
void setBackdrop(QString filename); void setBackdrop(QString filename);
bool hasBackdrop(){ return backdrop != 0; }
void makeCustomUI(QString id); void makeCustomUI(QString id);
static QColor stringToColor(QString str, QColor fallback); static QColor stringToColor(QString str, QColor fallback);
QColor foreground(){ return fgColor; }
QColor background(){ return bgColor; }
private: private:
int width; int width;

View file

@ -30,7 +30,10 @@
#include "skin_parser.h" #include "skin_parser.h"
RBViewport::RBViewport(skin_element* node, const RBRenderInfo& info) RBViewport::RBViewport(skin_element* node, const RBRenderInfo& info)
: QGraphicsItem(info.screen()) : QGraphicsItem(info.screen()), font(info.screen()->getFont(0)),
foreground(info.screen()->foreground()),
background(info.screen()->background()), textOffset(0,0),
screen(info.screen())
{ {
if(!node->tag) if(!node->tag)
{ {
@ -51,7 +54,7 @@ RBViewport::RBViewport(skin_element* node, const RBRenderInfo& info)
} }
else else
{ {
int param; int param = 0;
QString ident; QString ident;
int x,y,w,h; int x,y,w,h;
/* Rendering one of the other types of viewport */ /* Rendering one of the other types of viewport */
@ -102,6 +105,7 @@ RBViewport::RBViewport(skin_element* node, const RBRenderInfo& info)
setPos(x, y); setPos(x, y);
size = QRectF(0, 0, w, h); size = QRectF(0, 0, w, h);
} }
} }
@ -124,13 +128,29 @@ QRectF RBViewport::boundingRect() const
void RBViewport::paint(QPainter *painter, void RBViewport::paint(QPainter *painter,
const QStyleOptionGraphicsItem *option, QWidget *widget) const QStyleOptionGraphicsItem *option, QWidget *widget)
{ {
if(!screen->hasBackdrop() && background != screen->background())
{
painter->fillRect(size, QBrush(background));
}
painter->setBrush(Qt::NoBrush); painter->setBrush(Qt::NoBrush);
painter->setPen(customUI ? Qt::blue : Qt::red); painter->setPen(customUI ? Qt::blue : Qt::red);
painter->drawRect(size); painter->drawRect(size);
} }
/* Called at the end of a logical line */ void RBViewport::newLine()
void RBViewport::newline()
{ {
if(textOffset.x() > 0)
{
textOffset.setY(textOffset.y() + lineHeight);
textOffset.setX(0);
}
}
void RBViewport::write(QString text)
{
QGraphicsItem* graphic = font->renderText(text, foreground, this);
graphic->setPos(textOffset.x(), textOffset.y());
textOffset.setX(textOffset.x() + graphic->boundingRect().width());
lineHeight = font->lineHeight();
} }

View file

@ -23,6 +23,7 @@
#define RBVIEWPORT_H #define RBVIEWPORT_H
#include "skin_parser.h" #include "skin_parser.h"
#include "rbfont.h"
class RBScreen; class RBScreen;
class RBRenderInfo; class RBRenderInfo;
@ -45,16 +46,21 @@ public:
void makeCustomUI(){ customUI = true; } void makeCustomUI(){ customUI = true; }
void clearCustomUI(){ customUI = false; } void clearCustomUI(){ customUI = false; }
void newLine();
void newline(); void write(QString text);
private: private:
QRectF size; QRectF size;
QColor background; QColor background;
QColor foreground; QColor foreground;
RBFont* font;
bool customUI; bool customUI;
QPoint textOffset;
int lineHeight;
RBScreen* screen;
}; };
#endif // RBVIEWPORT_H #endif // RBVIEWPORT_H

View file

@ -44,7 +44,7 @@ DeviceState::DeviceState(QWidget *parent) :
this->setLayout(layout); this->setLayout(layout);
/* Loading the tabs */ /* Loading the tabs */
QScrollArea* currentArea; QScrollArea* currentArea = 0;
QHBoxLayout* subLayout; QHBoxLayout* subLayout;
QWidget* panel; QWidget* panel;
@ -176,7 +176,7 @@ DeviceState::DeviceState(QWidget *parent) :
{ {
elements = elements[1].trimmed().split(","); elements = elements[1].trimmed().split(",");
int defIndex; int defIndex = 0;
QComboBox* temp = new QComboBox(currentArea); QComboBox* temp = new QComboBox(currentArea);
for(int i = 0; i < elements.count(); i++) for(int i = 0; i < elements.count(); i++)
{ {

View file

@ -31,7 +31,8 @@
EditorWindow::EditorWindow(QWidget *parent) : EditorWindow::EditorWindow(QWidget *parent) :
QMainWindow(parent), QMainWindow(parent),
ui(new Ui::EditorWindow) ui(new Ui::EditorWindow),
parseTreeSelection(0)
{ {
ui->setupUi(this); ui->setupUi(this);
prefs = new PreferencesDialog(this); prefs = new PreferencesDialog(this);
@ -438,8 +439,6 @@ void EditorWindow::updateCurrent()
void EditorWindow::lineChanged(int line) void EditorWindow::lineChanged(int line)
{ {
ui->parseTree->collapseAll(); ui->parseTree->collapseAll();
if(parseTreeSelection)
parseTreeSelection->deleteLater();
ParseTreeModel* model = dynamic_cast<ParseTreeModel*> ParseTreeModel* model = dynamic_cast<ParseTreeModel*>
(ui->parseTree->model()); (ui->parseTree->model());
parseTreeSelection = new QItemSelectionModel(model); parseTreeSelection = new QItemSelectionModel(model);

View file

@ -516,7 +516,11 @@ void ParseTreeNode::render(const RBRenderInfo &info, RBViewport* viewport)
{ {
for(int i = 0; i < children.count(); i++) for(int i = 0; i < children.count(); i++)
children[i]->render(info, viewport); children[i]->render(info, viewport);
viewport->newline(); viewport->newLine();
}
else if(element->type == TEXT)
{
viewport->write(QString(static_cast<char*>(element->data)));
} }
else if(element->type == TAG) else if(element->type == TAG)
{ {