Show deco name and author info directly in each decoration preview.

svn path=/trunk/KDE/kdebase/workspace/; revision=1118057
This commit is contained in:
Martin Gräßlin 2010-04-23 19:20:01 +00:00
parent 4ce8401d45
commit 088757cd94
4 changed files with 68 additions and 5 deletions

View file

@ -29,9 +29,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <QtGui/QApplication>
#include <QtGui/QPainter>
#include <QtGui/QStyle>
#include <QtGui/QTextDocument>
// KDE
#include <KConfigGroup>
#include <KDesktopFile>
#include <KGlobalSettings>
#include <KIcon>
#include <KLocale>
#include <KStandardDirs>
@ -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( "<strong>%1</strong>" ).arg( data.name );
if( !data.author.isEmpty() )
{
QString authorCaption = i18nc( "Caption to decoration preview, %1 author name",
"by %1", data.author );
html += QString( "<br /><span style=\"font-size: %1pt;\">%2</span>" )
.arg( KGlobalSettings::smallestReadableFont().pointSize() )
.arg( authorCaption );
}
QColor color = QApplication::palette().brush( QPalette::Text ).color();
html = QString( "<div style=\"color: %1\" align=\"center\">%2</div>" ).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;
}

View file

@ -25,6 +25,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <KConfig>
#include <kdecoration.h>
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

View file

@ -38,6 +38,7 @@
#include <kdecoration_plugins_p.h>
#include <QX11Info>
#include <kwindowsystem.h>
#include <QTextDocument>
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<KDecorationUnstable *>( 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;
}

View file

@ -30,6 +30,7 @@
#include <kdecoration_plugins_p.h>
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* );