Commit 8db46900 authored by Mathias Soeken's avatar Mathias Soeken

I moved the menu items for setting color and font to a new config dialog....

I moved the menu items for setting color and font to a new config dialog. There will come some more 
options before KDE 4.3. And since color and font are long-term options, which does not need to be 
changed very often, it is a good place to stay in a config dialog.

But now you cannot see the change of the background color when you are choosing a color in the color 
dialog anymore. I will address this issue in the future.

svn path=/trunk/KDE/kdegraphics/kruler/; revision=908960
parent 2bc6ef02
......@@ -6,6 +6,8 @@ add_subdirectory( pics )
set(kruler_SRCS qautosizelabel.cpp klineal.cpp main.cpp)
kde4_add_ui_files(kruler_SRCS cfg_appearance.ui)
kde4_add_kcfg_files(kruler_SRCS kruler.kcfgc)
kde4_add_app_icon(kruler_SRCS "${CMAKE_CURRENT_SOURCE_DIR}/pics/hi*-apps-kruler.png")
......
TODO
* non-model preferences dialog, so that you can see the result when
you change the color
DONE
* Center scale
* Define scale offset
* Define offset via mouse wheel event
* Store last orientation and scale direction
* Store scale offset
* Relative scale (percent). Then ignoring offset?
<ui version="4.0" >
<author>Mathias Soeken</author>
<class>ConfigAppearance</class>
<widget class="QWidget" name="ConfigAppearance" >
<property name="geometry" >
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle" >
<string>Form</string>
</property>
<layout class="QFormLayout" name="formLayout" >
<property name="margin" >
<number>0</number>
</property>
<item row="0" column="0" >
<widget class="QLabel" name="label" >
<property name="text" >
<string>Background color:</string>
</property>
</widget>
</item>
<item row="0" column="1" >
<widget class="KColorButton" name="kcfg_BgColor" />
</item>
<item row="1" column="0" >
<widget class="QLabel" name="label_2" >
<property name="text" >
<string>Font:</string>
</property>
</widget>
</item>
<item row="1" column="1" >
<widget class="KFontRequester" name="kcfg_ScaleFont" />
</item>
</layout>
</widget>
<layoutfunction spacing="KDialog::spacingHint" margin="KDialog::marginHint" />
<customwidgets>
<customwidget>
<class>KColorButton</class>
<extends>QPushButton</extends>
<header>kcolorbutton.h</header>
</customwidget>
<customwidget>
<class>KFontRequester</class>
<extends>QWidget</extends>
<header>kfontrequester.h</header>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>kcfg_BgColor</tabstop>
</tabstops>
<includes/>
<resources/>
<connections/>
</ui>
......@@ -29,6 +29,7 @@
#include <KAction>
#include <KApplication>
#include <KConfig>
#include <KConfigDialog>
#include <KCursor>
#include <KFontDialog>
#include <KGlobalSettings>
......@@ -44,6 +45,8 @@
#include "kruler.h"
#include "qautosizelabel.h"
#include "ui_cfg_appearance.h"
/**
* this is our cursor bitmap:
* a line 48 pixels long with an arrow pointing down
......@@ -187,14 +190,7 @@ KLineal::KLineal( QWidget *parent )
new QShortcut( Qt::Key_O, this, SLOT( slotOffset() ) );
mMenu->addMenu( scaleMenu );
/*mMenu->addAction( KStandardAction::preferences( this, SLOT( slotPreferences() ), this ) );*/
mMenu->addAction( KIcon( "preferences-desktop-color" ),
i18n( "&Choose Color..." ), this, SLOT( chooseColor() ) );
mMenu->addAction( KIcon( "preferences-desktop-font" ),
i18n( "Choose &Font..." ), this, SLOT( chooseFont() ),
Qt::Key_F );
new QShortcut( Qt::Key_F, this, SLOT( chooseFont() ) );
mMenu->addAction( KStandardAction::preferences( this, SLOT( slotPreferences() ), this ) );
mMenu->addSeparator();
KAction *copyColorAction = KStandardAction::copy( this, SLOT( copyColor() ), this );
copyColorAction->setText( i18n( "Copy Color" ) );
......@@ -489,96 +485,34 @@ void KLineal::slotOffset()
}
}
void KLineal::switchRelativeScale( bool checked )
void KLineal::slotPreferences()
{
mRelativeScale = checked;
KConfigDialog *dialog = new KConfigDialog( this, "settings", RulerSettings::self() );
mCenterOriginAction->setEnabled( !mRelativeScale );
mOffsetAction->setEnabled( !mRelativeScale );
Ui::ConfigAppearance appearanceConfig;
QWidget *appearanceConfigWidget = new QWidget( dialog );
appearanceConfig.setupUi( appearanceConfigWidget );
dialog->addPage( appearanceConfigWidget, i18n( "Appearance" ), "preferences-desktop-default-applications" );
dialog->exec();
mColor = RulerSettings::self()->bgColor();
mScaleFont = RulerSettings::self()->scaleFont();
repaint();
adjustLabel();
saveSettings();
}
void KLineal::chooseColor()
void KLineal::switchRelativeScale( bool checked )
{
QRect r = KGlobalSettings::desktopGeometry( this );
QPoint pos = QCursor::pos();
if ( pos.x() + mColorSelector.width() > r.width() ) {
pos.setX( r.width() - mColorSelector.width() );
}
if ( pos.y() + mColorSelector.height() > r.height() ) {
pos.setY( r.height() - mColorSelector.height() );
}
mStoredColor = mColor;
mColorSelector.move( pos );
mColorSelector.setColor( mColor );
KConfigSkeletonItem *bgColorItem = RulerSettings::self()->findItem( "BgColor" );
if ( bgColorItem ) {
bgColorItem->swapDefault();
mColorSelector.setDefaultColor( RulerSettings::self()->bgColor() );
bgColorItem->swapDefault();
}
mColorSelector.show();
connect(&mColorSelector, SIGNAL(closeClicked()), this, SLOT(setColor()));
connect(&mColorSelector, SIGNAL(colorSelected(const QColor&)), this, SLOT(setColor(const QColor&)));
}
mRelativeScale = checked;
/**
* slot to choose a font
*/
void KLineal::chooseFont()
{
QFont font = mScaleFont;
int result = KFontDialog::getFont( font, false, this );
if ( result == KFontDialog::Accepted ) {
setFont( font );
}
}
mCenterOriginAction->setEnabled( !mRelativeScale );
mOffsetAction->setEnabled( !mRelativeScale );
/**
* set the ruler color to the previously selected color
*/
void KLineal::setFont( const QFont &font )
{
mScaleFont = font;
saveSettings();
repaint();
}
/**
* set the ruler color to the previously selected color
*/
void KLineal::setColor()
{
setColor( mColorSelector.color() );
adjustLabel();
saveSettings();
}
/**
* set the ruler color to some color
*/
void KLineal::setColor( const QColor &color )
{
if ( color.isValid() ) {
mColor = color;
} else {
KConfigSkeletonItem *bgColorItem = RulerSettings::self()->findItem( "BgColor" );
if ( bgColorItem ) {
bgColorItem->swapDefault();
mColor = RulerSettings::self()->bgColor();
bgColorItem->swapDefault();
}
}
repaint();
}
/**
* save the ruler color to the config file
*/
......@@ -594,14 +528,6 @@ void KLineal::saveSettings()
RulerSettings::self()->writeConfig();
}
/**
* restores the color
*/
void KLineal::restoreColor()
{
setColor( mStoredColor );
}
void KLineal::copyColor()
{
QApplication::clipboard()->setText( mColorLabel->text() );
......
......@@ -72,7 +72,6 @@ private:
QAction *mCenterOriginAction;
QAction *mOffsetAction;
QColor mColor;
QColor mStoredColor;
QCursor mCurrentCursor;
QCursor mNorthCursor;
QCursor mEastCursor;
......@@ -105,13 +104,8 @@ public slots:
void switchDirection();
void centerOrigin();
void slotOffset();
void slotPreferences();
void switchRelativeScale( bool checked );
void setColor();
void setFont( const QFont &font );
void setColor( const QColor &color );
void chooseColor();
void chooseFont();
void restoreColor();
void copyColor();
void saveSettings();
void slotQuit();
......
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE kcfg SYSTEM
<!DOCTYPE kcfg SYSTEM
"http://www.kde.org/standards/kcfg/1.0/kcfg.xsd">
<kcfg>
<kcfgfile name="krulerrc"/>
......@@ -15,7 +15,7 @@
</entry>
<entry name="ScaleFont" type="Font">
<label>Font of the text on the ruler scale.</label>
<default code="true">QFont( KGlobalSettings::generalFont().family(), 8 )</default>
<default code="true">QFont( KGlobalSettings::generalFont().family(), 6 )</default>
</entry>
<entry name="Orientation" type="Int">
<label>Orientation of the ruler</label>
......
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