Theme Editor: Removed markup comments from CodeEditor files (it was originally a Nokia example, so it was marked up with comments for their documentation), implemented the beginnings of drag and drop editing. Viewports are now movable, but don't invoke code generation yet

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@27675 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Robert Bieber 2010-08-03 08:42:30 +00:00
parent dad9810fe5
commit a83adc7d6d
5 changed files with 30 additions and 35 deletions

View file

@ -21,6 +21,11 @@
#include <QPainter> #include <QPainter>
#include <QPainterPath> #include <QPainterPath>
#include <QGraphicsSceneMouseEvent>
#include <QTransform>
#include <QDebug>
#include <cmath> #include <cmath>
#include "rbviewport.h" #include "rbviewport.h"
@ -40,6 +45,8 @@ RBViewport::RBViewport(skin_element* node, const RBRenderInfo& info)
statusBarTexture(":/render/statusbar.png"), statusBarTexture(":/render/statusbar.png"),
leftGraphic(0), centerGraphic(0), rightGraphic(0), scrollTime(0) leftGraphic(0), centerGraphic(0), rightGraphic(0), scrollTime(0)
{ {
setFlags(ItemIsSelectable | ItemIsMovable | ItemSendsGeometryChanges);
if(!node->tag) if(!node->tag)
{ {
/* Default viewport takes up the entire screen */ /* Default viewport takes up the entire screen */
@ -290,6 +297,26 @@ void RBViewport::showPlaylist(const RBRenderInfo &info, int start,
} }
} }
QVariant RBViewport::itemChange(GraphicsItemChange change,
const QVariant &value)
{
if(change == ItemPositionChange)
{
QPointF pos = value.toPointF();
QRectF bound = parentItem()->boundingRect();
pos.setX(qMax(0., pos.x()));
pos.setX(qMin(pos.x(), bound.width() - boundingRect().width()));
pos.setY(qMax(0., pos.y()));
pos.setY(qMin(pos.y(), bound.height() - boundingRect().height()));
return pos;
}
return QGraphicsItem::itemChange(change, value);
}
void RBViewport::alignLeft() void RBViewport::alignLeft()
{ {
int y = textOffset.y(); int y = textOffset.y();

View file

@ -77,6 +77,9 @@ public:
void showPlaylist(const RBRenderInfo& info, int start, skin_element* id3, void showPlaylist(const RBRenderInfo& info, int start, skin_element* id3,
skin_element* noId3); skin_element* noId3);
protected:
QVariant itemChange(GraphicsItemChange change, const QVariant &value);
private: private:
void alignLeft(); void alignLeft();

View file

@ -38,8 +38,6 @@
#include "codeeditor.h" #include "codeeditor.h"
//![constructor]
CodeEditor::CodeEditor(QWidget *parent) CodeEditor::CodeEditor(QWidget *parent)
: QPlainTextEdit(parent), completer(this) : QPlainTextEdit(parent), completer(this)
{ {
@ -58,10 +56,6 @@ CodeEditor::CodeEditor(QWidget *parent)
settings.beginGroup("CodeEditor"); settings.beginGroup("CodeEditor");
} }
//![constructor]
//![extraAreaWidth]
int CodeEditor::lineNumberAreaWidth() int CodeEditor::lineNumberAreaWidth()
{ {
int digits = 1; int digits = 1;
@ -76,19 +70,12 @@ int CodeEditor::lineNumberAreaWidth()
return space; return space;
} }
//![extraAreaWidth]
//![slotUpdateExtraAreaWidth]
void CodeEditor::updateLineNumberAreaWidth(int /* newBlockCount */) void CodeEditor::updateLineNumberAreaWidth(int /* newBlockCount */)
{ {
setViewportMargins(lineNumberAreaWidth(), 0, 0, 0); setViewportMargins(lineNumberAreaWidth(), 0, 0, 0);
} }
//![slotUpdateExtraAreaWidth]
//![slotUpdateRequest]
void CodeEditor::updateLineNumberArea(const QRect &rect, int dy) void CodeEditor::updateLineNumberArea(const QRect &rect, int dy)
{ {
if (dy) if (dy)
@ -100,8 +87,6 @@ void CodeEditor::updateLineNumberArea(const QRect &rect, int dy)
updateLineNumberAreaWidth(0); updateLineNumberAreaWidth(0);
} }
//![slotUpdateRequest]
void CodeEditor::cursorMoved() void CodeEditor::cursorMoved()
{ {
/* Closing the completer if the cursor has moved out of its bounds */ /* Closing the completer if the cursor has moved out of its bounds */
@ -138,8 +123,6 @@ void CodeEditor::insertTag()
completer.hide(); completer.hide();
} }
//![resizeEvent]
void CodeEditor::resizeEvent(QResizeEvent *e) void CodeEditor::resizeEvent(QResizeEvent *e)
{ {
QPlainTextEdit::resizeEvent(e); QPlainTextEdit::resizeEvent(e);
@ -149,8 +132,6 @@ void CodeEditor::resizeEvent(QResizeEvent *e)
lineNumberAreaWidth(), cr.height())); lineNumberAreaWidth(), cr.height()));
} }
//![resizeEvent]
void CodeEditor::keyPressEvent(QKeyEvent *event) void CodeEditor::keyPressEvent(QKeyEvent *event)
{ {
@ -256,23 +237,16 @@ void CodeEditor::keyPressEvent(QKeyEvent *event)
} }
//![extraAreaPaintEvent_0]
void CodeEditor::lineNumberAreaPaintEvent(QPaintEvent *event) void CodeEditor::lineNumberAreaPaintEvent(QPaintEvent *event)
{ {
QPainter painter(lineNumberArea); QPainter painter(lineNumberArea);
painter.fillRect(event->rect(), Qt::lightGray); painter.fillRect(event->rect(), Qt::lightGray);
//![extraAreaPaintEvent_0]
//![extraAreaPaintEvent_1]
QTextBlock block = firstVisibleBlock(); QTextBlock block = firstVisibleBlock();
int blockNumber = block.blockNumber(); int blockNumber = block.blockNumber();
int top = (int) blockBoundingGeometry(block).translated(contentOffset()).top(); int top = (int) blockBoundingGeometry(block).translated(contentOffset()).top();
int bottom = top + (int) blockBoundingRect(block).height(); int bottom = top + (int) blockBoundingRect(block).height();
//![extraAreaPaintEvent_1]
//![extraAreaPaintEvent_2]
while (block.isValid() && top <= event->rect().bottom()) { while (block.isValid() && top <= event->rect().bottom()) {
if (block.isVisible() && bottom >= event->rect().top()) { if (block.isVisible() && bottom >= event->rect().top()) {
QString number = QString::number(blockNumber + 1); QString number = QString::number(blockNumber + 1);
@ -293,5 +267,4 @@ void CodeEditor::lineNumberAreaPaintEvent(QPaintEvent *event)
++blockNumber; ++blockNumber;
} }
} }
//![extraAreaPaintEvent_2]

View file

@ -51,8 +51,6 @@ QT_END_NAMESPACE
class LineNumberArea; class LineNumberArea;
//![codeeditordefinition]
class CodeEditor : public QPlainTextEdit class CodeEditor : public QPlainTextEdit
{ {
Q_OBJECT Q_OBJECT
@ -91,9 +89,6 @@ private:
int docLength; int docLength;
}; };
//![codeeditordefinition]
//![extraarea]
class LineNumberArea : public QWidget class LineNumberArea : public QWidget
{ {
public: public:
@ -114,6 +109,4 @@ private:
CodeEditor *codeEditor; CodeEditor *codeEditor;
}; };
//![extraarea]
#endif #endif

View file

@ -35,7 +35,6 @@ SkinViewer::SkinViewer(QWidget *parent) :
QObject::connect(ui->zoomEvenButton, SIGNAL(pressed()), QObject::connect(ui->zoomEvenButton, SIGNAL(pressed()),
this, SLOT(zoomEven())); this, SLOT(zoomEven()));
ui->viewer->setDragMode(QGraphicsView::ScrollHandDrag);
} }
SkinViewer::~SkinViewer() SkinViewer::~SkinViewer()