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:
parent
691d049177
commit
273b9d6050
9 changed files with 70 additions and 15 deletions
|
@ -21,6 +21,9 @@
|
|||
|
||||
#include "rbfont.h"
|
||||
|
||||
#include <QFont>
|
||||
#include <QBrush>
|
||||
|
||||
RBFont::RBFont(QString file): filename(file)
|
||||
{
|
||||
}
|
||||
|
@ -28,3 +31,15 @@ RBFont::RBFont(QString file): filename(file)
|
|||
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;
|
||||
}
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
|
||||
#include <QString>
|
||||
#include <QFile>
|
||||
#include <QGraphicsSimpleTextItem>
|
||||
|
||||
class RBFont
|
||||
{
|
||||
|
@ -31,6 +32,10 @@ public:
|
|||
RBFont(QString file);
|
||||
virtual ~RBFont();
|
||||
|
||||
QGraphicsSimpleTextItem* renderText(QString text, QColor color,
|
||||
QGraphicsItem* parent = 0);
|
||||
int lineHeight(){ return 8; }
|
||||
|
||||
private:
|
||||
QString filename;
|
||||
};
|
||||
|
|
|
@ -32,10 +32,10 @@ RBScreen::RBScreen(const RBRenderInfo& info, QGraphicsItem *parent) :
|
|||
width = info.settings()->value("#screenwidth", "300").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);
|
||||
|
||||
QString fg = info.settings()->value("foreground color", "FFFFFF");
|
||||
QString fg = info.settings()->value("foreground color", "000000");
|
||||
fgColor = stringToColor(fg, Qt::black);
|
||||
|
||||
settings = info.settings();
|
||||
|
@ -61,6 +61,8 @@ RBScreen::RBScreen(const RBRenderInfo& info, QGraphicsItem *parent) :
|
|||
backdrop = 0;
|
||||
}
|
||||
}
|
||||
|
||||
fonts.insert(0, new RBFont("Nothin'"));
|
||||
}
|
||||
|
||||
RBScreen::~RBScreen()
|
||||
|
|
|
@ -60,10 +60,14 @@ public:
|
|||
RBFont* getFont(int id);
|
||||
|
||||
void setBackdrop(QString filename);
|
||||
bool hasBackdrop(){ return backdrop != 0; }
|
||||
void makeCustomUI(QString id);
|
||||
|
||||
static QColor stringToColor(QString str, QColor fallback);
|
||||
|
||||
QColor foreground(){ return fgColor; }
|
||||
QColor background(){ return bgColor; }
|
||||
|
||||
|
||||
private:
|
||||
int width;
|
||||
|
|
|
@ -30,7 +30,10 @@
|
|||
#include "skin_parser.h"
|
||||
|
||||
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)
|
||||
{
|
||||
|
@ -51,7 +54,7 @@ RBViewport::RBViewport(skin_element* node, const RBRenderInfo& info)
|
|||
}
|
||||
else
|
||||
{
|
||||
int param;
|
||||
int param = 0;
|
||||
QString ident;
|
||||
int x,y,w,h;
|
||||
/* Rendering one of the other types of viewport */
|
||||
|
@ -102,6 +105,7 @@ RBViewport::RBViewport(skin_element* node, const RBRenderInfo& info)
|
|||
|
||||
setPos(x, y);
|
||||
size = QRectF(0, 0, w, h);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -124,13 +128,29 @@ QRectF RBViewport::boundingRect() const
|
|||
void RBViewport::paint(QPainter *painter,
|
||||
const QStyleOptionGraphicsItem *option, QWidget *widget)
|
||||
{
|
||||
if(!screen->hasBackdrop() && background != screen->background())
|
||||
{
|
||||
painter->fillRect(size, QBrush(background));
|
||||
}
|
||||
|
||||
painter->setBrush(Qt::NoBrush);
|
||||
painter->setPen(customUI ? Qt::blue : Qt::red);
|
||||
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();
|
||||
}
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
#define RBVIEWPORT_H
|
||||
|
||||
#include "skin_parser.h"
|
||||
#include "rbfont.h"
|
||||
|
||||
class RBScreen;
|
||||
class RBRenderInfo;
|
||||
|
@ -45,16 +46,21 @@ public:
|
|||
void makeCustomUI(){ customUI = true; }
|
||||
void clearCustomUI(){ customUI = false; }
|
||||
|
||||
|
||||
void newline();
|
||||
void newLine();
|
||||
void write(QString text);
|
||||
|
||||
private:
|
||||
|
||||
QRectF size;
|
||||
QColor background;
|
||||
QColor foreground;
|
||||
RBFont* font;
|
||||
|
||||
bool customUI;
|
||||
QPoint textOffset;
|
||||
int lineHeight;
|
||||
|
||||
RBScreen* screen;
|
||||
};
|
||||
|
||||
#endif // RBVIEWPORT_H
|
||||
|
|
|
@ -44,7 +44,7 @@ DeviceState::DeviceState(QWidget *parent) :
|
|||
this->setLayout(layout);
|
||||
|
||||
/* Loading the tabs */
|
||||
QScrollArea* currentArea;
|
||||
QScrollArea* currentArea = 0;
|
||||
QHBoxLayout* subLayout;
|
||||
QWidget* panel;
|
||||
|
||||
|
@ -176,7 +176,7 @@ DeviceState::DeviceState(QWidget *parent) :
|
|||
{
|
||||
elements = elements[1].trimmed().split(",");
|
||||
|
||||
int defIndex;
|
||||
int defIndex = 0;
|
||||
QComboBox* temp = new QComboBox(currentArea);
|
||||
for(int i = 0; i < elements.count(); i++)
|
||||
{
|
||||
|
|
|
@ -31,7 +31,8 @@
|
|||
|
||||
EditorWindow::EditorWindow(QWidget *parent) :
|
||||
QMainWindow(parent),
|
||||
ui(new Ui::EditorWindow)
|
||||
ui(new Ui::EditorWindow),
|
||||
parseTreeSelection(0)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
prefs = new PreferencesDialog(this);
|
||||
|
@ -438,8 +439,6 @@ void EditorWindow::updateCurrent()
|
|||
void EditorWindow::lineChanged(int line)
|
||||
{
|
||||
ui->parseTree->collapseAll();
|
||||
if(parseTreeSelection)
|
||||
parseTreeSelection->deleteLater();
|
||||
ParseTreeModel* model = dynamic_cast<ParseTreeModel*>
|
||||
(ui->parseTree->model());
|
||||
parseTreeSelection = new QItemSelectionModel(model);
|
||||
|
|
|
@ -516,7 +516,11 @@ void ParseTreeNode::render(const RBRenderInfo &info, RBViewport* viewport)
|
|||
{
|
||||
for(int i = 0; i < children.count(); i++)
|
||||
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)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue