• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdesdk API Reference
  • KDE Home
  • Contact Us
 

lokalize

  • sources
  • kde-4.14
  • kdesdk
  • lokalize
  • src
  • common
flowlayout.cpp
Go to the documentation of this file.
1 /* ****************************************************************************
2  This file is part of KAider
3 
4  Copyright (C) 2007 by Nick Shaforostoff <shafff@ukr.net>
5  Copyright (C) 2004-2007 Trolltech ASA. All rights reserved.
6 
7  This program is free software; you can redistribute it and/or modify
8  it under the terms of the GNU General Public License as published by
9  the Free Software Foundation; either version 2 of the License, or
10  (at your option) any later version.
11 
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program; if not, write to the Free Software
19  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 
21  In addition, as a special exception, the copyright holders give
22  permission to link the code of this program with any edition of
23  the Qt library by Trolltech AS, Norway (or with modified versions
24  of Qt that use the same license as Qt), and distribute linked
25  combinations including the two. You must obey the GNU General
26  Public License in all respects for all of the code used other than
27  Qt. If you modify this file, you may extend this exception to
28  your version of the file, but you are not obligated to do so. If
29  you do not wish to do so, delete this exception statement from
30  your version.
31 
32 **************************************************************************** */
33 
34 #include "flowlayout.h"
35 #include "termlabel.h"
36 //#include "project.h"
37 
38 // #include <klocale.h>
39 #include <kdebug.h>
40 #include <kaction.h>
41 
42 using namespace GlossaryNS;
43 
44 FlowLayout::FlowLayout(User user,
45  QWidget *signalingWidget,
46  const QVector<KAction*>& actions,
47  int margin,
48  int spacing)
49  : QLayout()
50  , m_index(0)
51  , m_receiver(signalingWidget)
52 {
53  setSizeConstraint(QLayout::SetMinAndMaxSize);
54  setMargin(margin);
55  setSpacing(spacing);
56 
57  if (user==glossary)
58  {
59  foreach (KAction* action, actions)
60  {
61  TermLabel* label=new TermLabel(action); /*this,m_keys.at(count())*/
62  connect(action,SIGNAL(triggered(bool)),label,SLOT(insert()));
63  connect(label,SIGNAL(insertTerm(QString)),m_receiver,SIGNAL(termInsertRequested(QString)));
64  label->hide();
65  addWidget(label);
66  }
67  }
68 
69 // if (m_keys.isEmpty())
70 // {
71 // // Qt::Key key=Qt::Key_A;
72 // // for (;key<=Qt::Key_Z;++key)
73 // // {
74 // // if (KGlobalAccel::findActionNameSystemwide(Qt::ALT+key).isEmpty())
75 // // {
76 // // keys.append(key);
77 // // }
78 // // }
79 // int i=(int)Qt::Key_A;
80 // for (;i<=(int)Qt::Key_Z;++i)
81 // {
82 // if (KGlobalAccel::findActionNameSystemwide(Qt::ALT+Qt::CTRL+(Qt::Key)i).isEmpty())
83 // {
84 // m_keys.append((Qt::Key)i);
85 // }
86 // }
87 //
88 // }
89 
90 }
91 
92 
93 FlowLayout::~FlowLayout()
94 {
95  QLayoutItem *item;
96  while ((item = takeAt(0)))
97  delete item;
98 }
99 
100 QLayoutItem *FlowLayout::takeAt(int index)
101 {
102  if (index >= 0 && index < itemList.size())
103  return itemList.takeAt(index);
104  else
105  return 0;
106 }
107 
108 QLayoutItem *FlowLayout::itemAt(int index) const
109 {
110  return itemList.value(index);
111 }
112 
113 void FlowLayout::addItem(QLayoutItem *item) {itemList.append(item);}
114 int FlowLayout::count() const {return itemList.size();}
115 Qt::Orientations FlowLayout::expandingDirections() const {return 0;}
116 bool FlowLayout::hasHeightForWidth() const {return true;}
117 
118 int FlowLayout::heightForWidth(int width) const
119 {
120  int height = doLayout(QRect(0, 0, width, 0), true);
121  return height;
122 }
123 
124 void FlowLayout::setGeometry(const QRect &rect)
125 {
126  QLayout::setGeometry(rect);
127  doLayout(rect, false);
128 }
129 
130 QSize FlowLayout::sizeHint() const
131 {
132  return minimumSize();
133 }
134 
135 QSize FlowLayout::minimumSize() const
136 {
137  QSize size;
138  foreach (QLayoutItem* item, itemList)
139  size = size.expandedTo(item->minimumSize());
140 
141  size += QSize(2*margin(), 2*margin());
142  return size;
143 }
144 
145 int FlowLayout::doLayout(const QRect &rect, bool testOnly) const
146 {
147  int x = rect.x();
148  int y = rect.y();
149  int lineHeight = 0;
150 
151  foreach (QLayoutItem* item, itemList)
152  {
153  int nextX = x + item->sizeHint().width() + spacing();
154  if (nextX - spacing() > rect.right() && lineHeight > 0)
155  {
156  x = rect.x();
157  y = y + lineHeight + spacing();
158  nextX = x + item->sizeHint().width() + spacing();
159  lineHeight = 0;
160  }
161 
162  if (!testOnly)
163  item->setGeometry(QRect(QPoint(x, y), item->sizeHint()));
164 
165  x = nextX;
166  lineHeight = qMax(lineHeight, item->sizeHint().height());
167  }
168  return y + lineHeight - rect.y();
169 }
170 
171 void FlowLayout::clearTerms()
172 {
173  setEnabled(false);
174  foreach (QLayoutItem* item, itemList)
175  static_cast<TermLabel*>(item->widget())->hide();
176  m_index=0;
177  setEnabled(true);
178 }
179 
180 void FlowLayout::addTerm(const QString& term, const QByteArray& entryId, bool capFirst)
181 {
182  //fill layout with labels
183  while (m_index>=count())
184  {
185  TermLabel* label=new TermLabel;
186  connect(label,SIGNAL(insertTerm(QString)),m_receiver,SIGNAL(termInsertRequested(QString)));
187  addWidget(label);
188  }
189  TermLabel* label=static_cast<TermLabel*>(itemAt(m_index)->widget());
190  label->setText(term, entryId, capFirst);
191  label->show();
192  ++m_index;
193 }
194 
195 
QWidget
QSize::width
int width() const
Qt::Orientations
typedef Orientations
QRect::right
int right() const
QByteArray
QLayoutItem::setGeometry
virtual void setGeometry(const QRect &r)=0
QLayout::setEnabled
void setEnabled(bool enable)
QLayout::setSizeConstraint
void setSizeConstraint(SizeConstraint)
QLayoutItem::widget
virtual QWidget * widget()
QLayout
FlowLayout::addTerm
void addTerm(const QString &term, const QByteArray &entryId, bool capFirst=false)
Definition: flowlayout.cpp:180
FlowLayout::itemAt
QLayoutItem * itemAt(int index) const
Definition: flowlayout.cpp:108
FlowLayout::heightForWidth
int heightForWidth(int) const
Definition: flowlayout.cpp:118
term
static const QString term
Definition: glossary.cpp:48
QList::takeAt
T takeAt(int i)
QRect::x
int x() const
QRect::y
int y() const
QPoint
FlowLayout::~FlowLayout
~FlowLayout()
Definition: flowlayout.cpp:93
FlowLayout::User
User
Definition: flowlayout.h:51
QList::size
int size() const
QLayoutItem
QList::value
T value(int i) const
FlowLayout::glossary
Definition: flowlayout.h:53
termlabel.h
QRect
QList::append
void append(const T &value)
FlowLayout::FlowLayout
FlowLayout(User user=standard, QWidget *signalingWidget=0, const QVector< KAction * > &actions=QVector< KAction * >(), int margin=0, int spacing=-1)
c'tor for glossary view
Definition: flowlayout.cpp:44
FlowLayout::setGeometry
void setGeometry(const QRect &rect)
Definition: flowlayout.cpp:124
FlowLayout::addItem
void addItem(QLayoutItem *item)
Definition: flowlayout.cpp:113
QLayoutItem::minimumSize
virtual QSize minimumSize() const =0
FlowLayout::sizeHint
QSize sizeHint() const
Definition: flowlayout.cpp:130
FlowLayout::clearTerms
void clearTerms()
Definition: flowlayout.cpp:171
QString
QWidget::hide
void hide()
QLayout::setMargin
void setMargin(int margin)
QLayout::addWidget
void addWidget(QWidget *w)
FlowLayout::minimumSize
QSize minimumSize() const
Definition: flowlayout.cpp:135
QSize
GlossaryNS::TermLabel::setText
void setText(const QString &term, const QByteArray &entryId, bool capFirst)
Definition: termlabel.cpp:113
QVector< KAction * >
FlowLayout::expandingDirections
Qt::Orientations expandingDirections() const
Definition: flowlayout.cpp:115
QSize::expandedTo
QSize expandedTo(const QSize &otherSize) const
QSize::height
int height() const
FlowLayout::takeAt
QLayoutItem * takeAt(int index)
Definition: flowlayout.cpp:100
QLayout::setSpacing
void setSpacing(int)
QWidget::show
void show()
FlowLayout::hasHeightForWidth
bool hasHeightForWidth() const
Definition: flowlayout.cpp:116
flowlayout.h
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QLayout::setGeometry
virtual void setGeometry(const QRect &r)
QLayoutItem::sizeHint
virtual QSize sizeHint() const =0
FlowLayout::count
int count() const
Definition: flowlayout.cpp:114
GlossaryNS::TermLabel
flowlayout item
Definition: termlabel.h:36
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:40:07 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

lokalize

Skip menu "lokalize"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdesdk API Reference

Skip menu "kdesdk API Reference"
  • kapptemplate
  • kcachegrind
  • kompare
  • lokalize
  • umbrello
  •   umbrello

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal