[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: KDE/kdegraphics/okular/ui
From: Albert Astals Cid <tsdgeos () terra ! es>
Date: 2010-12-28 0:36:26
Message-ID: 20101228003626.0EE68AC8AD () svn ! kde ! org
[Download RAW message or body]
SVN commit 1209706 by aacid:
Update minibar page number when it has focus and page changes
Patch by Sebastian Dörner
M +29 -7 minibar.cpp
--- trunk/KDE/kdegraphics/okular/ui/minibar.cpp #1209705:1209706
@@ -48,7 +48,6 @@
private:
MiniBar * m_miniBar;
bool m_eatClick;
- QString backString;
QIntValidator * m_validator;
};
@@ -331,14 +330,39 @@
m_validator->setTop( pages );
}
-void PagesEdit::setText( const QString & text )
+void PagesEdit::setText( const QString & newText )
{
- // store a copy of the string
- backString = text;
// call default handler if hasn't focus
if ( !hasFocus() )
- KLineEdit::setText( text );
+ {
+ KLineEdit::setText( newText );
}
+ // else preserve existing selection
+ else
+ {
+ // save selection and adapt it to the new text length
+ int selectionLength = selectedText().length();
+ const bool allSelected = ( selectionLength == text().length() );
+ if ( allSelected )
+ {
+ KLineEdit::setText( newText );
+ selectAll();
+ }
+ else
+ {
+ int newSelectionStart = newText.length() - text().length() + \
selectionStart(); + if ( newSelectionStart < 0 )
+ {
+ // the new text is shorter than the old one, and the front part, \
which is "cut off", is selected + // shorten the selection accordingly
+ selectionLength += newSelectionStart;
+ newSelectionStart = 0;
+ }
+ KLineEdit::setText( newText );
+ setSelection( newSelectionStart, selectionLength );
+ }
+ }
+}
void PagesEdit::focusInEvent( QFocusEvent * e )
{
@@ -360,8 +384,6 @@
QPalette pal = palette();
pal.setColor( QPalette::Base, QApplication::palette().color( QPalette::Base \
).dark( 102 ) ); setPalette( pal );
- // restore text
- KLineEdit::setText( backString );
// call default handler
KLineEdit::focusOutEvent( e );
}
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic