[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: extragear/plasma/applets/notes
From: Sebastian Kügler <sebas () kde ! nl>
Date: 2008-04-28 23:44:55
Message-ID: 1209426295.568102.6153.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 802265 by sebas:
- textColor is now a member
- Add the option to have the fontsize dependant on the text,
makes the Note "zoomable", kind of.
M +53 -21 config.ui
M +46 -11 notes.cpp
M +5 -1 notes.h
--- trunk/extragear/plasma/applets/notes/config.ui #802264:802265
@@ -5,32 +5,64 @@
<rect>
<x>0</x>
<y>0</y>
- <width>300</width>
- <height>108</height>
+ <width>325</width>
+ <height>164</height>
</rect>
</property>
- <layout class="QGridLayout" name="gridLayout" >
- <item row="0" column="0" >
- <widget class="QLabel" name="textFontLabel" >
- <property name="text" >
- <string>Font:</string>
- </property>
- </widget>
+ <layout class="QVBoxLayout" name="verticalLayout" >
+ <item>
+ <layout class="QHBoxLayout" name="horizontalLayout_2" >
+ <item>
+ <widget class="QLabel" name="textFontLabel" >
+ <property name="text" >
+ <string>Font:</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="KFontRequester" name="textFontButton" />
+ </item>
+ </layout>
</item>
- <item row="0" column="1" >
- <widget class="KFontRequester" name="textFontButton" />
+ <item>
+ <layout class="QHBoxLayout" name="horizontalLayout_3" >
+ <item>
+ <widget class="QCheckBox" name="autoFont" >
+ <property name="acceptDrops" >
+ <bool>false</bool>
+ </property>
+ <property name="text" >
+ <string>Set font size automatically</string>
+ </property>
+ <property name="checked" >
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QSpinBox" name="autoFontPercent" >
+ <property name="suffix" >
+ <string>%</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
</item>
- <item row="1" column="0" >
- <widget class="QLabel" name="textColorLabel" >
- <property name="text" >
- <string>Text Color:</string>
- </property>
- </widget>
+ <item>
+ <layout class="QHBoxLayout" name="horizontalLayout" >
+ <item>
+ <widget class="QLabel" name="textColorLabel" >
+ <property name="text" >
+ <string>Text Color:</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="KColorButton" name="textColorButton" />
+ </item>
+ </layout>
</item>
- <item row="1" column="1" >
- <widget class="KColorButton" name="textColorButton" />
- </item>
- <item row="2" column="0" colspan="2" >
+ <item>
<widget class="QCheckBox" name="checkSpelling" >
<property name="text" >
<string>Check spelling</string>
--- trunk/extragear/plasma/applets/notes/notes.cpp #802264:802265
@@ -24,6 +24,7 @@
#include <QGraphicsLinearLayout>
#include <QGraphicsTextItem>
+#include <KGlobalSettings>
#include <KConfigDialog>
#include <KConfigGroup>
#include <KFontDialog>
@@ -43,6 +44,7 @@
m_textEdit = new KTextEdit();
m_layout = new QGraphicsLinearLayout();
m_proxy = new QGraphicsProxyWidget(this);
+ m_autoFont = false;
updateTextGeometry();
}
@@ -66,10 +68,11 @@
if (! text.isEmpty()) {
m_textEdit->setPlainText(text);
}
- QFont font = cg.readEntry("font", QFont());
- m_textEdit->setFont(font);
- QColor textColor = cg.readEntry("textcolor", QColor(Qt::black));
- m_textEdit->setTextColor(textColor);
+ m_font = cg.readEntry("font", KGlobalSettings::generalFont());
+ m_autoFont = cg.readEntry("autoFont", true);
+ m_autoFontPercent = cg.readEntry("autoFontPercent", 5);
+ m_textColor = cg.readEntry("textcolor", QColor(Qt::black));
+ m_textEdit->setTextColor(m_textColor);
m_checkSpelling = cg.readEntry("checkSpelling", false);
m_textEdit->setCheckSpellingEnabled(m_checkSpelling);
setLayout(m_layout);
@@ -92,8 +95,22 @@
const qreal ypad = geometry().height() / 15;
m_layout->setSpacing(xpad);
m_layout->setContentsMargins(xpad, ypad, xpad, ypad);
+ m_font.setPointSize(fontSize());
+ m_textEdit->setFont(m_font);
}
+int Notes::fontSize()
+{
+ if (m_autoFont) {
+ int geo = qMax(geometry().width(), geometry().height());
+ int size = qMax(KGlobalSettings::smallestReadableFont().pointSize(), \
qRound(geo*m_autoFontPercent/100)); + kDebug() << size << \
geo*m_autoFontPercent << geo << m_autoFontPercent << geometry(); + return \
size; + } else {
+ return m_font.pointSize();
+ }
+}
+
void Notes::saveNote()
{
KConfigGroup cg = config();
@@ -104,7 +121,6 @@
Notes::~Notes()
{
- emit configNeedsSaving();
//FIXME is it really ok to save from here?
//also, this has a really weird effect: if I remove a note then add a new one, I \
can get the old
//text back. it was useful when there were load/save issues but it's silly now.
@@ -129,8 +145,10 @@
parent->addPage(widget, parent->windowTitle(), "notes");
connect(parent, SIGNAL(applyClicked()), this, SLOT(configAccepted()));
connect(parent, SIGNAL(okClicked()), this, SLOT(configAccepted()));
- ui.textColorButton->setColor(m_textEdit->textColor());
+ ui.textColorButton->setColor(m_textColor);
ui.textFontButton->setFont(m_textEdit->font());
+ ui.autoFont->setChecked(m_autoFont);
+ ui.autoFontPercent->setValue(m_autoFontPercent);
ui.checkSpelling->setChecked(m_checkSpelling);
}
@@ -141,29 +159,46 @@
bool changed = false;
QFont newFont = ui.textFontButton->font();
- if (m_textEdit->currentFont() != newFont) {
+ if (m_font != newFont) {
changed = true;
cg.writeEntry("font", newFont);
+ m_font = newFont;
+ m_font.setPointSize(fontSize());
m_textEdit->setFont(newFont);
}
+ if (m_autoFont == ui.autoFont->isChecked()) {
+ changed = true;
+ m_autoFont = ui.autoFont->isChecked();
+ cg.writeEntry("autoFont", m_autoFont);
+ }
+
+ if (m_autoFontPercent != ui.autoFontPercent->value()) {
+ changed = true;
+ m_autoFontPercent = (ui.autoFontPercent->value());
+ cg.writeEntry("autoFontPercent", m_autoFontPercent);
+ }
+
QColor newColor = ui.textColorButton->color();
kDebug() << m_textEdit->textColor() << newColor;
- if (m_textEdit->textColor() != newColor) {
+ if (m_textColor != newColor) {
changed = true;
- cg.writeEntry("textcolor", newColor);
- m_textEdit->setTextColor(newColor);
+ m_textColor = newColor;
+ cg.writeEntry("textcolor", m_textColor);
+ m_textEdit->setTextColor(m_textColor);
}
bool spellCheck = ui.checkSpelling->isChecked();
if (spellCheck != m_checkSpelling) {
+ changed = true;
m_checkSpelling = spellCheck;
cg.writeEntry("checkSpelling", m_checkSpelling);
m_textEdit->setCheckSpellingEnabled(m_checkSpelling);
- changed = true;
}
if (changed) {
+ kDebug() << "autoFont" << m_autoFont << m_autoFontPercent << \
ui.autoFontPercent->value(); + updateTextGeometry();
emit configNeedsSaving();
}
}
--- trunk/extragear/plasma/applets/notes/notes.h #802264:802265
@@ -57,14 +57,18 @@
void createConfigurationInterface(KConfigDialog *parent);
private:
+ int fontSize();
+ int m_autoFontPercent;
+ bool m_autoFont;
bool m_checkSpelling;
void updateTextGeometry();
+ QFont m_font;
+ QColor m_textColor;
Plasma::Svg m_notes_theme;
QGraphicsLinearLayout *m_layout;
QGraphicsProxyWidget *m_proxy;
KTextEdit *m_textEdit;
Ui::config ui;
- //KDialog *m_dialog;
QSizeF m_size;
};
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic