diff --git a/kcmkwin/kwindecoration/decorationmodel.cpp b/kcmkwin/kwindecoration/decorationmodel.cpp index c120c6bca6..ad4ee096e6 100644 --- a/kcmkwin/kwindecoration/decorationmodel.cpp +++ b/kcmkwin/kwindecoration/decorationmodel.cpp @@ -29,9 +29,11 @@ along with this program. If not, see . #include #include #include +#include // KDE #include #include +#include #include #include #include @@ -48,6 +50,7 @@ DecorationModel::DecorationModel( KSharedConfigPtr config, QObject* parent ) , m_rightButtons( QString() ) , m_theme( new Aurorae::AuroraeTheme( this ) ) , m_scene( new Aurorae::AuroraeScene( m_theme, QString(), QString(), true, this ) ) + , m_renderWidget( new QWidget( 0 ) ) { m_config = KSharedConfig::openConfig( "auroraerc" ); m_scene->setIcon( KIcon( "xorg" ) ); @@ -58,6 +61,7 @@ DecorationModel::~DecorationModel() { delete m_preview; delete m_plugins; + delete m_renderWidget; } void DecorationModel::reload() @@ -276,6 +280,27 @@ void DecorationModel::regeneratePreviews() void DecorationModel::regeneratePreview( const QModelIndex& index, const QSize& size ) { DecorationModelData& data = m_decorations[ index.row() ]; + //Use a QTextDocument to layout the text + QTextDocument document; + + QString html = QString( "%1" ).arg( data.name ); + + if( !data.author.isEmpty() ) + { + QString authorCaption = i18nc( "Caption to decoration preview, %1 author name", + "by %1", data.author ); + + html += QString( "
%2" ) + .arg( KGlobalSettings::smallestReadableFont().pointSize() ) + .arg( authorCaption ); + } + + QColor color = QApplication::palette().brush( QPalette::Text ).color(); + html = QString( "
%2
" ).arg( color.name() ).arg( html ); + + document.setHtml( html ); + const int margin = 5; + switch( data.type ) { case DecorationModelData::NativeDecoration: @@ -289,7 +314,7 @@ void DecorationModel::regeneratePreview( const QModelIndex& index, const QSize& m_preview->resize( size ); m_preview->setTempButtons( m_plugins, m_customButtons, m_leftButtons, m_rightButtons ); m_preview->setTempBorderSize( m_plugins, data.borderSize ); - data.preview = m_preview->preview(); + data.preview = m_preview->preview( &document, m_renderWidget ); break; case DecorationModelData::AuroraeDecoration: { @@ -309,16 +334,31 @@ void DecorationModel::regeneratePreview( const QModelIndex& index, const QSize& size.width() - xoffset - 20 + padLeft + padRight, size.height() - top - 20 + padLeft + padRight ); m_scene->setActive( false, false ); - m_scene->setCaption( data.name + " - " + i18n( "Inactive Window" ) ); + m_scene->setCaption( i18n( "Inactive Window" ) ); m_scene->setButtons( m_customButtons ? m_leftButtons : m_theme->defaultButtonsLeft(), m_customButtons ? m_rightButtons : m_theme->defaultButtonsRight()); QPainter painter( &pix ); QRect rect = QRectF( QPointF( 10 + xoffset - padLeft, 10 - padTop ), m_scene->sceneRect().size() ).toRect(); m_scene->render( &painter, QStyle::visualRect( QApplication::layoutDirection(), pix.rect(), rect )); m_scene->setActive( true, false ); - m_scene->setCaption( data.name + " - " + i18n( "Active Window" ) ); + m_scene->setCaption( i18n( "Active Window" ) ); rect = QRectF( QPointF( 10 - padLeft, top + 10 - padTop ), m_scene->sceneRect().size() ).toRect(); m_scene->render( &painter, QStyle::visualRect( QApplication::layoutDirection(), pix.rect(), rect )); + + const int width = rect.width() - left - right - padLeft - padRight; + const int height = rect.height() - top - bottom -padTop - padBottom; + m_renderWidget->setGeometry( 0, 0, width, height ); + painter.save(); + const QPoint topLeft = QStyle::visualRect( QApplication::layoutDirection(), pix.rect(), rect ).topLeft() + + QPoint( left + padLeft, top + padTop ); + m_renderWidget->render( &painter, topLeft ); + painter.restore(); + //Enable word-wrap + document.setTextWidth( width - margin * 2 ); + painter.save(); + painter.translate( topLeft ); + document.drawContents( &painter, QRectF( margin, margin, width - margin * 2, height - margin * 2 )); + painter.restore(); data.preview = pix; break; } diff --git a/kcmkwin/kwindecoration/decorationmodel.h b/kcmkwin/kwindecoration/decorationmodel.h index 67ef511957..9888ec731f 100644 --- a/kcmkwin/kwindecoration/decorationmodel.h +++ b/kcmkwin/kwindecoration/decorationmodel.h @@ -25,6 +25,7 @@ along with this program. If not, see . #include #include +class QWidget; class KDesktopFile; class KDecorationPlugins; class KDecorationPreview; @@ -128,6 +129,7 @@ class DecorationModel : public QAbstractListModel Aurorae::AuroraeTheme* m_theme; Aurorae::AuroraeScene* m_scene; KSharedConfigPtr m_config; + QWidget* m_renderWidget; }; } // namespace KWin diff --git a/kcmkwin/kwindecoration/preview.cpp b/kcmkwin/kwindecoration/preview.cpp index ca4856d52d..d875e8a67a 100644 --- a/kcmkwin/kwindecoration/preview.cpp +++ b/kcmkwin/kwindecoration/preview.cpp @@ -38,6 +38,7 @@ #include #include #include +#include KDecorationPreview::KDecorationPreview( QWidget* parent ) : QWidget( parent ) @@ -123,7 +124,7 @@ void KDecorationPreview::paintEvent( QPaintEvent* e ) } } -QPixmap KDecorationPreview::preview() +QPixmap KDecorationPreview::preview( QTextDocument* document, QWidget* widget ) { QPixmap pixmap( size() ); pixmap.fill( Qt::transparent ); @@ -137,6 +138,25 @@ QPixmap KDecorationPreview::preview() { QWidget *w = deco[Active]->widget(); w->render( &pixmap, w->mapToParent( QPoint(0, 0) ) ); + int left, right, top, bottom; + deco[Active]->borders( left, right, top, bottom ); + int padLeft, padRight, padTop, padBottom; + padLeft = padRight = padTop = padBottom = 0; + if( KDecorationUnstable *unstable = qobject_cast( deco[Active] ) ) + { + unstable->padding( padLeft, padRight, padTop, padBottom ); + } + widget->setGeometry( 0, 0, + w->geometry().width() - left - right - padLeft - padRight, + w->geometry().height() - top - bottom - padTop - padBottom ); + QPoint topLeft = w->geometry().topLeft() + QPoint( left + padLeft, top + padTop ); + widget->render( &pixmap, topLeft ); + //Enable word-wrap + const int margin = 5; + document->setTextWidth( widget->width() - margin * 2 ); + QPainter painter( &pixmap ); + painter.translate( topLeft ); + document->drawContents( &painter, widget->geometry().adjusted( margin, margin, -margin, -margin )); } return pixmap; } diff --git a/kcmkwin/kwindecoration/preview.h b/kcmkwin/kwindecoration/preview.h index f0f57ee9e0..e87a9bc832 100644 --- a/kcmkwin/kwindecoration/preview.h +++ b/kcmkwin/kwindecoration/preview.h @@ -30,6 +30,7 @@ #include class QLabel; +class QTextDocument; class KDecorationPreviewBridge; class KDecorationPreviewOptions; @@ -54,7 +55,7 @@ class KDecorationPreview QRect windowGeometry( bool ) const; void setTempBorderSize(KDecorationPlugins* plugin, KDecorationDefines::BorderSize size); void setTempButtons(KDecorationPlugins* plugin, bool customEnabled, const QString &left, const QString &right); - QPixmap preview(); + QPixmap preview(QTextDocument* document, QWidget* widget); protected: virtual void paintEvent( QPaintEvent* ); virtual void resizeEvent( QResizeEvent* );