~ubuntu-branches/ubuntu/natty/kdenetwork/natty-proposed

« back to all changes in this revision

Viewing changes to filesharing/simple/krichtextlabel.cpp

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2011-02-21 14:26:58 UTC
  • Revision ID: package-import@ubuntu.com-20110221142658-mzt9flk82tzdunxj
Tags: 4:4.6.0-0ubuntu4
Update kubuntu_05_samba_sharing.diff to match master

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* This file is part of the KDE libraries
2
 
   Copyright (C) 2005 Waldo Bastian <bastian@kde.org>
3
 
 
4
 
   This library is free software; you can redistribute it and/or
5
 
   modify it under the terms of the GNU Library General Public
6
 
   License version 2 as published by the Free Software Foundation.
7
 
 
8
 
   This library is distributed in the hope that it will be useful,
9
 
   but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11
 
   Library General Public License for more details.
12
 
 
13
 
   You should have received a copy of the GNU Library General Public License
14
 
   along with this library; see the file COPYING.LIB.  If not, write to
15
 
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16
 
   Boston, MA 02110-1301, USA.
17
 
*/
18
 
 
19
 
#include "krichtextlabel.h"
20
 
#include <QTextDocument>
21
 
 
22
 
 
23
 
#include <q3stylesheet.h>
24
 
#include <q3simplerichtext.h>
25
 
#include <qtextdocument.h>
26
 
//Added by qt3to4:
27
 
#include <QLabel>
28
 
 
29
 
#include <kglobalsettings.h>
30
 
 
31
 
static QString qrichtextify( const QString& text )
32
 
{
33
 
  if ( text.isEmpty() || text[0] == '<' )
34
 
    return text;
35
 
 
36
 
  QStringList lines = QStringList::split('\n', text);
37
 
  for(QStringList::Iterator it = lines.begin(); it != lines.end(); ++it)
38
 
  {
39
 
    *it = Qt::convertFromPlainText( *it, Qt::WhiteSpaceNormal );
40
 
  }
41
 
 
42
 
  return lines.join(QString::null);     //krazy:exclude=nullstrassign for old broken gcc
43
 
}
44
 
 
45
 
KRichTextLabel::KRichTextLabel( const QString &text , QWidget *parent )
46
 
 : QLabel ( parent ) {
47
 
  m_defaultWidth = qMin(400, KGlobalSettings::desktopGeometry(this).width()*2/5);
48
 
  setWordWrap( true );
49
 
  setText(text);
50
 
}
51
 
 
52
 
KRichTextLabel::KRichTextLabel( QWidget *parent )
53
 
 : QLabel ( parent ) {
54
 
  m_defaultWidth = qMin(400, KGlobalSettings::desktopGeometry(this).width()*2/5);
55
 
  setWordWrap( true );
56
 
}
57
 
 
58
 
void KRichTextLabel::setDefaultWidth(int defaultWidth)
59
 
{
60
 
  m_defaultWidth = defaultWidth;
61
 
  updateGeometry();
62
 
}
63
 
 
64
 
QSizePolicy KRichTextLabel::sizePolicy() const
65
 
{
66
 
  return QSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Minimum, false);
67
 
}
68
 
 
69
 
QSize KRichTextLabel::minimumSizeHint() const
70
 
{
71
 
  QString qt_text = qrichtextify( text() );
72
 
  int pref_width = 0;
73
 
  int pref_height = 0;
74
 
  QTextDocument rt;
75
 
  rt.setHtml( qt_text );
76
 
 
77
 
  pref_width = m_defaultWidth;
78
 
  rt.setTextWidth(pref_width);
79
 
  int used_width = rt.idealWidth();
80
 
  if (used_width <= pref_width)
81
 
  {
82
 
    while(true)
83
 
    {
84
 
      int new_width = (used_width * 9) / 10;
85
 
      rt.setTextWidth(new_width);
86
 
      int new_height = rt.size().height();
87
 
      if (new_height > pref_height)
88
 
        break;
89
 
      used_width = rt.idealWidth();
90
 
      if (used_width > new_width)
91
 
        break;
92
 
    }
93
 
    pref_width = used_width;
94
 
  }
95
 
  else
96
 
  {
97
 
    if (used_width > (pref_width *2))
98
 
      pref_width = pref_width *2;
99
 
    else
100
 
      pref_width = used_width;
101
 
  }
102
 
 
103
 
  return QSize(pref_width, rt.size().height());
104
 
}
105
 
 
106
 
QSize KRichTextLabel::sizeHint() const
107
 
{
108
 
  return minimumSizeHint();
109
 
}
110
 
 
111
 
void KRichTextLabel::setText( const QString &text ) {
112
 
  QLabel::setText(text);
113
 
}
114
 
 
115
 
void KRichTextLabel::virtual_hook( int, void* )
116
 
{ /*BASE::virtual_hook( id, data );*/ }
117
 
 
118
 
#include "krichtextlabel.moc"