Commit 1fc49220 authored by Robert Knight's avatar Robert Knight
Browse files

Live previews of color schemes and fonts. Moving the mouse over a color...

Live previews of color schemes and fonts.  Moving the mouse over a color scheme in the list temporarily changes the colors of all open terminal displays using the current profile to that color scheme.

svn path=/branches/work/konsole-split-view/; revision=660879
parent d3a09212
......@@ -18,6 +18,7 @@
*/
// Qt
#include <QHideEvent>
#include <QLinearGradient>
#include <QPainter>
#include <QStandardItemModel>
......@@ -255,9 +256,14 @@ void EditProfileDialog::setupAppearencePage(const Profile* info)
_ui->colorSchemeList->setModel(model);
_ui->colorSchemeList->setItemDelegate(new ColorSchemeViewDelegate(this));
_ui->colorSchemeList->setMouseTracking(true);
_ui->colorSchemeList->installEventFilter(this);
connect( _ui->colorSchemeList , SIGNAL(doubleClicked(const QModelIndex&)) , this ,
SLOT(colorSchemeSelected()) );
connect( _ui->colorSchemeList , SIGNAL(entered(const QModelIndex&)) , this ,
SLOT(previewColorScheme(const QModelIndex&)) );
connect( _ui->selectColorSchemeButton , SIGNAL(clicked()) , this ,
SLOT(colorSchemeSelected()) );
connect( _ui->editColorSchemeButton , SIGNAL(clicked()) , this ,
......@@ -277,6 +283,63 @@ void EditProfileDialog::setupAppearencePage(const Profile* info)
connect( _ui->editFontButton , SIGNAL(clicked()) , this ,
SLOT(showFontDialog()) );
}
bool EditProfileDialog::eventFilter( QObject* watched , QEvent* event )
{
if ( watched == _ui->colorSchemeList && event->type() == QEvent::Leave )
{
unpreview(Profile::ColorScheme);
}
return KDialog::eventFilter(watched,event);
}
void EditProfileDialog::hideEvent(QHideEvent* event)
{
qDebug() << "unpreviewing";
QHash<Profile::Property,QVariant> map;
QHashIterator<int,QVariant> iter(_previewedProperties);
while ( iter.hasNext() )
{
iter.next();
map.insert((Profile::Property)iter.key(),iter.value());
}
// undo any preview changes
if ( !_previewedProperties.isEmpty() )
SessionManager::instance()->changeProfile(_profileKey,map,false);
event->accept();
}
void EditProfileDialog::unpreview(int property)
{
if (!_previewedProperties.contains(property))
return;
QHash<Profile::Property,QVariant> map;
map.insert((Profile::Property)property,_previewedProperties[property]);
SessionManager::instance()->changeProfile(_profileKey,map,false);
_previewedProperties.remove(property);
}
void EditProfileDialog::preview(int property , QVariant value)
{
QHash<Profile::Property,QVariant> map;
map.insert((Profile::Property)property,value);
const Profile* original = SessionManager::instance()->profile(_profileKey);
if (!_previewedProperties.contains(property))
_previewedProperties.insert(property , original->property((Profile::Property)property) );
// temporary change to color scheme
SessionManager::instance()->changeProfile( _profileKey , map , false);
}
void EditProfileDialog::previewColorScheme(const QModelIndex& index)
{
const QString& name = index.data(Qt::UserRole+1).value<const ColorScheme*>()->name();
preview( Profile::ColorScheme , name );
}
void EditProfileDialog::removeColorScheme()
{
QModelIndexList selected = _ui->colorSchemeList->selectionModel()->selectedIndexes();
......@@ -522,15 +585,24 @@ void EditProfileDialog::toggleResizeWindow(bool enable)
{
_tempProfile->setProperty(Profile::AllowProgramsToResizeWindow,enable);
}
#if 0
void EditProfileDialog::previewFont(const QFont& font)
{
preview(Profile::Font,font);
}
#endif
void EditProfileDialog::showFontDialog()
{
//TODO Only permit selection of mono-spaced fonts.
// the KFontDialog API does not appear to have a means to do this
// at present.
QFont currentFont = _ui->fontPreviewLabel->font();
if ( KFontDialog::getFont(currentFont) == KFontDialog::Accepted )
KFontDialog dialog;
if ( dialog.exec() == KFontDialog::Accepted )
{
QFont currentFont = dialog.font();
QSlider* slider = _ui->fontSizeSlider;
_ui->fontSizeSlider->setRange( qMin(slider->minimum(),currentFont.pointSize()) ,
......@@ -539,6 +611,8 @@ void EditProfileDialog::showFontDialog()
_ui->fontPreviewLabel->setFont(currentFont);
_tempProfile->setProperty(Profile::Font,currentFont);
preview(Profile::Font,currentFont);
}
}
void EditProfileDialog::setFontSize(int pointSize)
......@@ -548,6 +622,8 @@ void EditProfileDialog::setFontSize(int pointSize)
_ui->fontPreviewLabel->setFont( newFont );
_tempProfile->setProperty(Profile::Font,newFont);
preview(Profile::Font,newFont);
}
ColorSchemeViewDelegate::ColorSchemeViewDelegate(QObject* parent)
: QAbstractItemDelegate(parent)
......
......@@ -23,6 +23,7 @@
// Qt
#include <QAbstractItemDelegate>
#include <QPair>
#include <QHash>
#include <QSet>
// KDE
......@@ -68,6 +69,10 @@ public:
public slots:
virtual void accept();
protected:
virtual void hideEvent(QHideEvent* event);
virtual bool eventFilter(QObject* watched , QEvent* event);
private slots:
// saves changes to profile
void save();
......@@ -97,6 +102,8 @@ private slots:
void editColorScheme();
void removeColorScheme();
void colorSchemeSelected();
void previewColorScheme(const QModelIndex& index);
//void previewFont(const QFont&);
// scrolling page
void noScrollBack();
......@@ -131,6 +138,9 @@ private:
void showColorSchemeEditor(bool newScheme);
void preview(int property , QVariant value);
void unpreview(int property);
struct RadioOption
{
QAbstractButton* button;
......@@ -149,6 +159,8 @@ private:
Ui::EditProfileDialog* _ui;
Profile* _tempProfile;
QString _profileKey;
QHash<int,QVariant> _previewedProperties;
};
/**
......
......@@ -554,7 +554,7 @@ void SessionManager::saveProfile(const QString& path , Profile* info)
}
void SessionManager::changeProfile(const QString& key ,
QHash<Profile::Property,QVariant> propertyMap)
QHash<Profile::Property,QVariant> propertyMap, bool persistant)
{
Profile* info = profile(key);
......@@ -582,18 +582,21 @@ void SessionManager::changeProfile(const QString& key ,
// notify the world about the change
emit profileChanged(key);
// save the changes to disk
// the path may be empty here, in which case it is up
// to the profile writer to generate or request a path name
if ( info->isPropertySet(Profile::Path) )
{
qDebug() << "Profile saved to existing path: " << info->path();
saveProfile(info->path(),info);
}
else
if ( persistant )
{
qDebug() << "Profile saved to new path.";
saveProfile(QString::null,info);
// save the changes to disk
// the path may be empty here, in which case it is up
// to the profile writer to generate or request a path name
if ( info->isPropertySet(Profile::Path) )
{
qDebug() << "Profile saved to existing path: " << info->path();
saveProfile(info->path(),info);
}
else
{
qDebug() << "Profile saved to new path.";
saveProfile(QString::null,info);
}
}
}
void SessionManager::applyProfile(const QString& key , bool modifiedPropertiesOnly)
......
......@@ -492,8 +492,10 @@ public:
*
* @param key The profile's key
* @param propertyMap A map between profile properties and values describing the changes
* @param persistant If true, the changes are saved to the profile's configuration file
*/
void changeProfile(const QString& key , QHash<Profile::Property,QVariant> propertyMap);
void changeProfile(const QString& key , QHash<Profile::Property,QVariant> propertyMap,
bool persistant = true);
/**
* Returns a Profile object describing the default type of session, which is used
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment