From kfm-devel Fri Aug 09 21:41:29 2002 From: Waldo Bastian Date: Fri, 09 Aug 2002 21:41:29 +0000 To: kfm-devel Subject: Re: PATCH: Default progress dialog X-MARC-Message: https://marc.info/?l=kfm-devel&m=102892951813588 MIME-Version: 1 Content-Type: multipart/mixed; boundary="--Boundary-00=_JcDV9tTwdPQdcvN" --Boundary-00=_JcDV9tTwdPQdcvN Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline On Thursday 08 August 2002 06:08 pm, Waldo Bastian wrote: > On Thursday 08 August 2002 05:04 pm, Dawit A. wrote: > > On Wednesday 07 August 2002 16:29, Martijn Klingens wrote: > > > On Wednesday 07 August 2002 07:27, Dawit A. wrote: > > > > The attached patch changes the squeezed labels to read-only lineedit > > > > in the progress dialog so that one can copy either URL as needed. > > > > See attached screenshot. > > > > > > Doesn't the active label that e.g. KMessageBox uses look nicer (less > > > full of widgets, because of all borders). Apart from that, nice > > > feature! :) > > > > The active label is a multiline label box. It would be an over kill to > > use it here. The frame on the line edit can be changed to look like a > > label, but then the user would not be able to distinguish this from any > > normal label. > > I think it looks nice in your screenshot. > > Although I think it would look nicer if it was squeezed but in such a way > that selecting the text would select the original URL instead of the > squeezed one. > > I can make that I think. Yay... aply patch and use setSqueezedText() instead of setText() It sets a tooltip with the full text and selecting the thing also selects t= he=20 full text instead of the "..." part. It adjusts accordingly when resized. Cheers, Waldo =2D-=20 bastian@kde.org | SuSE Labs KDE Developer | bastian@suse.com --Boundary-00=_JcDV9tTwdPQdcvN Content-Type: text/x-diff; charset="iso-8859-1"; name="klineedit_squeeze.diff" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="klineedit_squeeze.diff" Index: klineedit.cpp =================================================================== RCS file: /home/kde/kdelibs/kdeui/klineedit.cpp,v retrieving revision 1.146 diff -u -p -r1.146 klineedit.cpp --- klineedit.cpp 2002/06/19 17:55:54 1.146 +++ klineedit.cpp 2002/08/09 21:37:41 @@ -27,7 +27,7 @@ #include #include - +#include #include #include #include @@ -59,6 +59,9 @@ public: bool grabReturnKeyEvents; bool handleURLDrops; KCompletionBox *completionBox; + QString squeezedText; + int squeezedStart; + int squeezedEnd; }; @@ -187,6 +190,112 @@ void KLineEdit::setReadOnly(bool readOnl setPalette(p); QLineEdit::setReadOnly (readOnly); +} + +void KLineEdit::setSqueezedText( const QString &text) +{ + d->squeezedText = text; + d->squeezedStart = 0; + d->squeezedEnd = 0; + if (isVisible()) + { + QResizeEvent ev(size(), size()); + resizeEvent(&ev); + } +} + +void KLineEdit::copy() const +{ + if (!d->squeezedText.isEmpty() && d->squeezedStart) + { + int start, end; + KLineEdit *that = const_cast(this); + if (!that->getSelection(&start, &end)) + return; + if (start >= d->squeezedStart+3) + start = start - 3 - d->squeezedStart + d->squeezedEnd; + else if (start > d->squeezedStart) + start = d->squeezedStart; + if (end >= d->squeezedStart+3) + end = end - 3 - d->squeezedStart + d->squeezedEnd; + else if (end > d->squeezedStart) + end = d->squeezedEnd; + if (start == end) + return; + QString t = d->squeezedText; + t = t.mid(start, end - start); + disconnect( QApplication::clipboard(), SIGNAL(selectionChanged()), this, 0); + QApplication::clipboard()->setText( t ); + connect( QApplication::clipboard(), SIGNAL(selectionChanged()), + this, SLOT(clipboardChanged()) ); + } + else + { + QLineEdit::copy(); + } +} + +void KLineEdit::resizeEvent( QResizeEvent * ev ) +{ + if (!d->squeezedText.isEmpty()) + { + d->squeezedStart = 0; + d->squeezedEnd = 0; + QString fullText = d->squeezedText; + QFontMetrics fm(fontMetrics()); + int labelWidth = size().width() - 2*frameWidth() - 2; + int textWidth = fm.width(fullText); + if (textWidth > labelWidth) { + // start with the dots only + QString squeezedText = "..."; + int squeezedWidth = fm.width(squeezedText); + + // estimate how many letters we can add to the dots on both sides + int letters = fullText.length() * (labelWidth - squeezedWidth) / textWidth / 2; + squeezedText = fullText.left(letters) + "..." + fullText.right(letters); + squeezedWidth = fm.width(squeezedText); + + if (squeezedWidth < labelWidth) { + // we estimated too short + // add letters while text < label + do { + letters++; + squeezedText = fullText.left(letters) + "..." + fullText.right(letters); + squeezedWidth = fm.width(squeezedText); + } while (squeezedWidth < labelWidth); + letters--; + squeezedText = fullText.left(letters) + "..." + fullText.right(letters); + } else if (squeezedWidth > labelWidth) { + // we estimated too long + // remove letters while text > label + do { + letters--; + squeezedText = fullText.left(letters) + "..." + fullText.right(letters); + squeezedWidth = fm.width(squeezedText); + } while (squeezedWidth > labelWidth); + } + + if (letters < 5) { + // too few letters added -> we give up squeezing + setText(fullText); + } else { + setText(squeezedText); + d->squeezedStart = letters; + d->squeezedEnd = fullText.length() - letters; + } + + QToolTip::remove( this ); + QToolTip::add( this, fullText ); + + } else { + setText(fullText); + + QToolTip::remove( this ); + QToolTip::hide(); + } + setCursorPosition(0); + } + QLineEdit::resizeEvent(ev); } void KLineEdit::keyPressEvent( QKeyEvent *e ) Index: klineedit.h =================================================================== RCS file: /home/kde/kdelibs/kdeui/klineedit.h,v retrieving revision 1.93 diff -u -p -r1.93 klineedit.h --- klineedit.h 2002/08/01 14:19:52 1.93 +++ klineedit.h 2002/08/09 21:37:41 @@ -271,6 +271,10 @@ public: */ virtual void setCompletionObject( KCompletion *, bool hsig = true ); + /** + * Reimplemented for internal reasons, the API is not affected. + */ + virtual void copy() const; signals: @@ -370,6 +374,12 @@ public slots: * (changing the clipboard to the text we just had in the lineedit) */ virtual void clear(); + + /** + * Squeezes @p text into the line edit. + * This can only be used with read-only line-edits. + */ + void setSqueezedText( const QString &text); protected slots: @@ -390,6 +400,13 @@ protected slots: void slotCancelled() {} protected: + + /** + * Re-implemented for internal reasons. API not affected. + * + * See @ref QLineEdit::resizeEvent(). + */ + virtual void resizeEvent( QResizeEvent * ); /** * Re-implemented for internal reasons. API not affected. --Boundary-00=_JcDV9tTwdPQdcvN--