diff --git a/utils/themeeditor/graphics/rbviewport.cpp b/utils/themeeditor/graphics/rbviewport.cpp index e9c58eb6fb..f7b1bc4ca2 100644 --- a/utils/themeeditor/graphics/rbviewport.cpp +++ b/utils/themeeditor/graphics/rbviewport.cpp @@ -21,6 +21,11 @@ #include #include +#include +#include + +#include + #include #include "rbviewport.h" @@ -40,6 +45,8 @@ RBViewport::RBViewport(skin_element* node, const RBRenderInfo& info) statusBarTexture(":/render/statusbar.png"), leftGraphic(0), centerGraphic(0), rightGraphic(0), scrollTime(0) { + setFlags(ItemIsSelectable | ItemIsMovable | ItemSendsGeometryChanges); + if(!node->tag) { /* 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() { int y = textOffset.y(); diff --git a/utils/themeeditor/graphics/rbviewport.h b/utils/themeeditor/graphics/rbviewport.h index c665108618..ea47225f09 100644 --- a/utils/themeeditor/graphics/rbviewport.h +++ b/utils/themeeditor/graphics/rbviewport.h @@ -77,6 +77,9 @@ public: void showPlaylist(const RBRenderInfo& info, int start, skin_element* id3, skin_element* noId3); +protected: + QVariant itemChange(GraphicsItemChange change, const QVariant &value); + private: void alignLeft(); diff --git a/utils/themeeditor/gui/codeeditor.cpp b/utils/themeeditor/gui/codeeditor.cpp index 3858460385..9a2a0182f2 100644 --- a/utils/themeeditor/gui/codeeditor.cpp +++ b/utils/themeeditor/gui/codeeditor.cpp @@ -38,8 +38,6 @@ #include "codeeditor.h" -//![constructor] - CodeEditor::CodeEditor(QWidget *parent) : QPlainTextEdit(parent), completer(this) { @@ -58,10 +56,6 @@ CodeEditor::CodeEditor(QWidget *parent) settings.beginGroup("CodeEditor"); } -//![constructor] - -//![extraAreaWidth] - int CodeEditor::lineNumberAreaWidth() { int digits = 1; @@ -76,19 +70,12 @@ int CodeEditor::lineNumberAreaWidth() return space; } -//![extraAreaWidth] - -//![slotUpdateExtraAreaWidth] void CodeEditor::updateLineNumberAreaWidth(int /* newBlockCount */) { setViewportMargins(lineNumberAreaWidth(), 0, 0, 0); } -//![slotUpdateExtraAreaWidth] - -//![slotUpdateRequest] - void CodeEditor::updateLineNumberArea(const QRect &rect, int dy) { if (dy) @@ -100,8 +87,6 @@ void CodeEditor::updateLineNumberArea(const QRect &rect, int dy) updateLineNumberAreaWidth(0); } -//![slotUpdateRequest] - void CodeEditor::cursorMoved() { /* Closing the completer if the cursor has moved out of its bounds */ @@ -138,8 +123,6 @@ void CodeEditor::insertTag() completer.hide(); } -//![resizeEvent] - void CodeEditor::resizeEvent(QResizeEvent *e) { QPlainTextEdit::resizeEvent(e); @@ -149,8 +132,6 @@ void CodeEditor::resizeEvent(QResizeEvent *e) lineNumberAreaWidth(), cr.height())); } -//![resizeEvent] - void CodeEditor::keyPressEvent(QKeyEvent *event) { @@ -256,23 +237,16 @@ void CodeEditor::keyPressEvent(QKeyEvent *event) } -//![extraAreaPaintEvent_0] - void CodeEditor::lineNumberAreaPaintEvent(QPaintEvent *event) { QPainter painter(lineNumberArea); painter.fillRect(event->rect(), Qt::lightGray); -//![extraAreaPaintEvent_0] - -//![extraAreaPaintEvent_1] QTextBlock block = firstVisibleBlock(); int blockNumber = block.blockNumber(); int top = (int) blockBoundingGeometry(block).translated(contentOffset()).top(); int bottom = top + (int) blockBoundingRect(block).height(); -//![extraAreaPaintEvent_1] -//![extraAreaPaintEvent_2] while (block.isValid() && top <= event->rect().bottom()) { if (block.isVisible() && bottom >= event->rect().top()) { QString number = QString::number(blockNumber + 1); @@ -293,5 +267,4 @@ void CodeEditor::lineNumberAreaPaintEvent(QPaintEvent *event) ++blockNumber; } } -//![extraAreaPaintEvent_2] diff --git a/utils/themeeditor/gui/codeeditor.h b/utils/themeeditor/gui/codeeditor.h index 21f1c561cf..9968cf5093 100644 --- a/utils/themeeditor/gui/codeeditor.h +++ b/utils/themeeditor/gui/codeeditor.h @@ -51,8 +51,6 @@ QT_END_NAMESPACE class LineNumberArea; -//![codeeditordefinition] - class CodeEditor : public QPlainTextEdit { Q_OBJECT @@ -91,9 +89,6 @@ private: int docLength; }; -//![codeeditordefinition] -//![extraarea] - class LineNumberArea : public QWidget { public: @@ -114,6 +109,4 @@ private: CodeEditor *codeEditor; }; -//![extraarea] - #endif diff --git a/utils/themeeditor/gui/skinviewer.cpp b/utils/themeeditor/gui/skinviewer.cpp index 95caf1e393..1d5c84c519 100644 --- a/utils/themeeditor/gui/skinviewer.cpp +++ b/utils/themeeditor/gui/skinviewer.cpp @@ -35,7 +35,6 @@ SkinViewer::SkinViewer(QWidget *parent) : QObject::connect(ui->zoomEvenButton, SIGNAL(pressed()), this, SLOT(zoomEven())); - ui->viewer->setDragMode(QGraphicsView::ScrollHandDrag); } SkinViewer::~SkinViewer()