From b5abdc24780c81c800b62bb98a2b2adbe2df8a2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Minisini?= Date: Sun, 20 Feb 2011 22:04:23 +0000 Subject: [PATCH] [GB.FORM] * NEW: the text of IconView items is now automatically ellipsized. [GB.QT4] * BUG: Rich text size is now computed with no default margin around the text. git-svn-id: svn://localhost/gambas/trunk@3585 867c0c6c-44f3-4631-809d-bfa615b0a4ec --- TODO | 2 - comp/src/gb.form/.info | 4 ++ comp/src/gb.form/.lang/.pot | 12 ------ comp/src/gb.form/.project | 4 +- comp/src/gb.form/.src/IconView/IconView.class | 7 +++- .../gb.form/.src/IconView/_IconViewItem.class | 40 +++++++++++++++++-- comp/src/gb.form/.src/Test/FMain.form | 29 ++------------ gb.qt4/src/CDraw.cpp | 2 + gb.qt4/src/CFont.cpp | 1 + 9 files changed, 55 insertions(+), 46 deletions(-) diff --git a/TODO b/TODO index 0f79f8ff3..16a6468fe 100644 --- a/TODO +++ b/TODO @@ -44,8 +44,6 @@ GUI RELATED STUFF - ListView and GridView selection interface should be the same. - Keep ListView.SelectAll(Boolean) for compatibility. - Remove ScreenShot() method. -- Fix infinite loop when clicking with the right mouse button in an iconview. -- Clean up gb.db.form component. Use the Proxy property in controls. DESKTOP COMPONENT diff --git a/comp/src/gb.form/.info b/comp/src/gb.form/.info index 8636fd6c4..a1395eb8a 100644 --- a/comp/src/gb.form/.info +++ b/comp/src/gb.form/.info @@ -2238,3 +2238,7 @@ MoveLast m +_IsEllipsized +m +b + diff --git a/comp/src/gb.form/.lang/.pot b/comp/src/gb.form/.lang/.pot index 07b02431c..8c80e9b3b 100644 --- a/comp/src/gb.form/.lang/.pot +++ b/comp/src/gb.form/.lang/.pot @@ -207,18 +207,6 @@ msgstr "" msgid "How quickly daft jumping zebras vex" msgstr "" -#: FMain.class:27 -msgid "Item 0" -msgstr "" - -#: FMain.class:34 -msgid "Item 1" -msgstr "" - -#: FMain.class:41 -msgid "Item 2" -msgstr "" - #: FMessage.class:132 msgid "Do not display this message again" msgstr "" diff --git a/comp/src/gb.form/.project b/comp/src/gb.form/.project index 04fb451be..8987ae53c 100644 --- a/comp/src/gb.form/.project +++ b/comp/src/gb.form/.project @@ -1,7 +1,7 @@ # Gambas Project File 3.0 # Compiled with Gambas 2.99.0 Title=More controls for graphical components -Startup=FIconView +Startup=FMain Version=2.99.0 VersionProgram=gbx3 -V Component=gb.image @@ -9,7 +9,7 @@ Component=gb.gui Component=gb.form Component=gb.settings Authors="Benoît Minisini" -Environment="GB_GUI=gb.gtk" +Environment="GB_GUI=gb.qt4" TabSize=2 Translate=1 Language=en diff --git a/comp/src/gb.form/.src/IconView/IconView.class b/comp/src/gb.form/.src/IconView/IconView.class index 4f6b591a3..d6c787d44 100644 --- a/comp/src/gb.form/.src/IconView/IconView.class +++ b/comp/src/gb.form/.src/IconView/IconView.class @@ -562,6 +562,8 @@ End Private Sub SetHoverItem(iPos As Integer) + Dim hItem As _IconViewItem + If iPos = $iHover Then Return Swap iPos, $iHover @@ -570,7 +572,10 @@ Private Sub SetHoverItem(iPos As Integer) RefreshIcon($iHover) $hView.Tooltip = "" - If $iHover >= 0 Then $hView.Tooltip = $aItems[$iHover].Text + If $iHover >= 0 Then + hItem = $aItems[$iHover] + If hItem._IsEllipsized() Then $hView.Tooltip = hItem.Text + Endif End diff --git a/comp/src/gb.form/.src/IconView/_IconViewItem.class b/comp/src/gb.form/.src/IconView/_IconViewItem.class index 48537e9b2..dd60a723a 100644 --- a/comp/src/gb.form/.src/IconView/_IconViewItem.class +++ b/comp/src/gb.form/.src/IconView/_IconViewItem.class @@ -20,6 +20,7 @@ Private $sText As String Private $hPicture As Picture Private $bSelected As Boolean Private $bEditable As Boolean +Private $bEllipsized As Boolean Event _Foo @@ -207,9 +208,10 @@ End Public Sub _Draw(hRect As Rect, hClip As Rect, hIconView As IconView, bHorizontal As Boolean, bFocus As Boolean, bHover As Boolean) - Dim X, Y, W As Integer + Dim X, Y, W, H, HT As Integer Dim iColor As Integer Dim bFrame As Boolean + Dim sText As String hRect.Adjust(4) @@ -288,12 +290,24 @@ Public Sub _Draw(hRect As Rect, hClip As Rect, hIconView As IconView, bHorizonta If $sText Then 'Draw.Clip(hRect.X, Y, hRect.W, hRect.H - Y) Draw.Font = hIconView.Font + + sText = $sText + + H = Draw.Font.RichTextHeight(sText, hRect.W) + HT = hRect.H - (Y - hRect.Y) + If H > HT Then + sText = Ellipsize(sText, Draw.Font, hRect.W, HT) + $bEllipsized = True + Else + $bEllipsized = False + Endif + If Not bFrame Then Draw.Foreground = If($bSelected, Color.SelectedBackground, Color.TextBackground) - Draw.RichText($sText, hRect.X + 1, Y + 1, hRect.W, hRect.H - (Y - hRect.Y), Align.Top) + Draw.RichText(sText, hRect.X + 1, Y + 1, hRect.W, HT, Align.Top) Endif Draw.Foreground = If($bSelected, Color.SelectedForeground, Color.TextForeground) - Draw.RichText($sText, hRect.X, Y, hRect.W, hRect.H - (Y - hRect.Y), Align.Top) + Draw.RichText(sText, hRect.X, Y, hRect.W, HT, Align.Top) 'Draw.Clip.Enabled = False Endif @@ -458,3 +472,23 @@ Public Sub MoveLast() End +Private Sub Ellipsize(sText As String, hFont As Font, W As Integer, H As Integer) As String + + Dim sCar As String = "…" + Dim iPos As Integer + + If Not sText Then Return + + For iPos = 1 To Len(sText) + If hFont.RichTextHeight(Left(sText, iPos) & sCar, W) > H Then Break + Next + + Return Left(sText, iPos - 1) & sCar + +End + +Public Sub _IsEllipsized() As Boolean + + Return $bEllipsized + +End diff --git a/comp/src/gb.form/.src/Test/FMain.form b/comp/src/gb.form/.src/Test/FMain.form index 834f77792..34b459759 100644 --- a/comp/src/gb.form/.src/Test/FMain.form +++ b/comp/src/gb.form/.src/Test/FMain.form @@ -2,33 +2,10 @@ { Form Form MoveScaled(0,0,96,51) - Arrangement = Arrange.Horizontal + Arrangement = Arrange.Fill Spacing = True Margin = True - { IconPanel1 IconPanel - MoveScaled(5,5,79,40) - Expand = True - Arrangement = Arrange.Fill - Count = 3 - Border = True - Index = 0 - Text = ("Item 0") - Picture = Picture["icon:/large/access"] - { Button1 Button - MoveScaled(1,3,16,4) - } - Index = 1 - Text = ("Item 1") - Picture = Picture["icon:/large/battery"] - { TextBox1 TextBox - MoveScaled(2,9,24,4) - } - Index = 2 - Text = ("Item 2") - Picture = Picture["icon:/large/book"] - { ColorChooser1 ColorChooser - MoveScaled(1,1,49,36) - } - Index = 0 + { FileChooser1 FileChooser + MoveScaled(5,2,64,46) } } diff --git a/gb.qt4/src/CDraw.cpp b/gb.qt4/src/CDraw.cpp index 4c6bca3ac..8f4b3009c 100644 --- a/gb.qt4/src/CDraw.cpp +++ b/gb.qt4/src/CDraw.cpp @@ -892,6 +892,7 @@ void DRAW_rich_text(QPainter *p, const QString &text, float x, float y, float w, t = "
" + t + "
"; QTextDocument rt; + rt.setDocumentMargin(0); rt.setHtml(t); rt.setDefaultFont(p->font()); @@ -938,6 +939,7 @@ static void rich_text_size(GB_DRAW *d, char *text, int len, int sw, int *w, int { QTextDocument rt; + rt.setDocumentMargin(0); rt.setHtml(QString::fromUtf8((const char *)text, len)); rt.setDefaultFont(DP(d)->font()); diff --git a/gb.qt4/src/CFont.cpp b/gb.qt4/src/CFont.cpp index fbc18f6eb..83db1c2f8 100644 --- a/gb.qt4/src/CFont.cpp +++ b/gb.qt4/src/CFont.cpp @@ -439,6 +439,7 @@ static void rich_text_size(CFONT *_object, char *text, int len, int sw, int *w, { QTextDocument rt; + rt.setDocumentMargin(0); rt.setHtml(QString::fromUtf8((const char *)text, len)); rt.setDefaultFont(*(THIS->font));