Libkdepim

multiplyinglineeditor.cpp
1 /*
2  Copyright (C) 2010 Casey Link <[email protected]>
3  Copyright (C) 2009-2010 Klaralvdalens Datakonsult AB, a KDAB Group company <[email protected]>
4 
5  Refactored from earlier code by:
6  Copyright (c) 2010 Volker Krause <[email protected]>
7  Copyright (c) 2004 Cornelius Schumacher <[email protected]>
8 
9  This library is free software; you can redistribute it and/or modify it
10  under the terms of the GNU Library General Public License as published by
11  the Free Software Foundation; either version 2 of the License, or (at your
12  option) any later version.
13 
14  This library is distributed in the hope that it will be useful, but WITHOUT
15  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
17  License for more details.
18 
19  You should have received a copy of the GNU Library General Public License
20  along with this library; see the file COPYING.LIB. If not, write to the
21  Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22  02110-1301, USA.
23 */
24 
25 #include "multiplyinglineeditor.h"
26 #include "multiplyinglineview_p.h"
27 
28 #include <QHBoxLayout>
29 using namespace KPIM;
30 MultiplyingLineEditor::MultiplyingLineEditor(MultiplyingLineFactory *factory, QWidget *parent)
31  : QWidget(parent)
32  , mMultiplyingLineFactory(factory)
33 {
34  QBoxLayout *topLayout = new QHBoxLayout(this);
35  topLayout->setContentsMargins(0, 0, 0, 0);
36 
37  mView = new MultiplyingLineView(mMultiplyingLineFactory, this);
38  topLayout->addWidget(mView);
39  connect(mView, &MultiplyingLineView::focusUp, this, &MultiplyingLineEditor::focusUp);
40  connect(mView, &MultiplyingLineView::focusDown, this, &MultiplyingLineEditor::focusDown);
41  connect(mView, &MultiplyingLineView::completionModeChanged,
42  this, &MultiplyingLineEditor::completionModeChanged);
43  connect(mView, &MultiplyingLineView::lineDeleted, this, &MultiplyingLineEditor::lineDeleted);
44  connect(mView, &MultiplyingLineView::lineAdded, this, &MultiplyingLineEditor::lineAdded);
45  connect(mView, &MultiplyingLineView::sizeHintChanged,
46  this, &MultiplyingLineEditor::sizeHintChanged);
47 }
48 
49 MultiplyingLineEditor::~MultiplyingLineEditor()
50 {
51  delete mMultiplyingLineFactory;
52 }
53 
55 {
56  MultiplyingLine *line = mView->emptyLine();
57  bool tooManyAddress = false;
58  if (!line) {
59  line = mView->addLine();
60  }
61  if (!line) {
62  tooManyAddress = true;
63  }
64  if (line && data) {
65  line->setData(data);
66  }
67  return tooManyAddress;
68 }
69 
71 {
72  mView->removeData(data);
73 }
74 
76 {
77  const auto lstLines = mView->lines();
78  for (MultiplyingLine *line : lstLines) {
79  line->slotPropagateDeletion();
80  }
81 }
82 
84 {
85  return mModified || mView->isModified();
86 }
87 
89 {
90  mModified = false;
91  mView->clearModified();
92 }
93 
94 void MultiplyingLineEditor::setFocus()
95 {
96  mView->setFocus();
97 }
98 
99 void MultiplyingLineEditor::setFocusTop()
100 {
101  mView->setFocusTop();
102 }
103 
104 void MultiplyingLineEditor::setFocusBottom()
105 {
106  mView->setFocusBottom();
107 }
108 
110 {
111  return mView->setFirstColumnWidth(w);
112 }
113 
115 {
116  mView->setCompletionMode(mode);
117 }
118 
120 {
121  return mMultiplyingLineFactory;
122 }
123 
125 {
126  return mView->allData();
127 }
128 
130 {
131  return mView->activeLine()->data();
132 }
133 
134 QList< MultiplyingLine * > MultiplyingLineEditor::lines() const
135 {
136  return mView->lines();
137 }
138 
139 MultiplyingLine *MultiplyingLineEditor::activeLine() const
140 {
141  return mView->activeLine();
142 }
143 
145 {
146  mView->setFrameStyle(shape);
147 }
148 
150 {
151  mView->setAutoResize(resize);
152 }
153 
154 bool MultiplyingLineEditor::autoResizeView()
155 {
156  return mView->autoResize();
157 }
158 
160 {
161  mView->setDynamicSizeHint(dynamic);
162 }
163 
164 bool MultiplyingLineEditor::dynamicSizeHint() const
165 {
166  return mView->dynamicSizeHint();
167 }
void resize(int w, int h)
void setContentsMargins(int left, int top, int right, int bottom)
void setDynamicSizeHint(bool dynamic)
Sets whether the size hint of the editor shall be calculated dynamically by the number of lines...
bool isModified()
Returns true if the user has made any modifications to the list of recipients.
void setCompletionMode(KCompletion::CompletionMode mode)
Set completion mode for all lines.
void setAutoResizeView(bool resize)
Make the line view follow it&#39;s children&#39;s size.
T * data() const const
void clearModified()
Resets the modified flag to false.
void addWidget(QWidget *widget, int stretch, Qt::Alignment alignment)
MultiplyingLineData::Ptr activeData() const
Retrieve the data of the active line.
An Abstract Base Class used to create MultiplyingLines Subclass this class and MultiplyingLine, then implement newLine() such that it allocates and returns an instance of your MultiplyingLine.
virtual void setData(const MultiplyingLineData::Ptr &data)=0
Set the data of this line.
int setFirstColumnWidth(int w)
Set the width of the left most column to be the argument width.
bool addData(const MultiplyingLineData::Ptr &data=MultiplyingLineData::Ptr())
Adds data to one line of the editor.
Abstract Base Class representing a line in the Multiplying line widget.
Class KCheckComboBox::Private.
Definition: kcursorsaver.h:24
void removeData(const MultiplyingLineData::Ptr &data)
Removes data provided it can be found.
QVector< MultiplyingLineData::Ptr > allData() const
Retrieve the data from the editor.
MultiplyingLineFactory * factory() const
Get the current line factory for this instance of the widget.
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
virtual MultiplyingLineData::Ptr data() const =0
Retrieve the data.
void clear()
Clear all lines from the widget.
void setFrameStyle(int shape)
Set the underlying view&#39;s frame shape, default is none.
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Fri Jul 10 2020 23:16:21 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.