2 * Copyright (C) 2008 David Greaves
4 * This software is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public License
6 * as published by the Free Software Foundation; either version 2.1 of
7 * the License, or (at your option) any later version.
9 * This software is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this software; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 //#define DEBUG_SHOPPER 1
21 #include "shopper.h" // automake, i8n, gettext
22 #include "LabelEntry.h"
24 #include "GestureWatcher.h"
28 // SLabel a label that emits pressed() when clicked
29 SLabel::SLabel(QWidget
* parent
, Qt::WindowFlags f
) :
33 SLabel::SLabel( const QString
& text
, QWidget
* parent
, Qt::WindowFlags f
) :
34 QLabel(text
, parent
, f
)
37 void SLabel::setVisible(bool vis
)
39 QLabel::setVisible(vis
);
41 void SLabel::mouseReleaseEvent ( QMouseEvent
* event
)
43 if (event
->button() == Qt::LeftButton
) {
50 // LabelEntry - a label that turns into a textbox when clicked
51 LabelEntry::LabelEntry(QWidget
*parent
) :
59 LabelEntry::LabelEntry(const QString
& value
, QWidget
*parent
) :
67 void LabelEntry::init()
69 myLabel
= new SLabel(data
, this);
70 GestureWatcher
* gw
= GestureWatcher::getGestureWatcher();
71 gw
->connect(myLabel
, Gesture("r l "),
72 this, SLOT(label_clicked()));
73 gw
->connect(myLabel
, Gesture("l r "),
74 this, SLOT(label_clicked()));
75 // connect(myLabel, SIGNAL(pressed()),
76 // this, SLOT(label_clicked()));
77 layout
.addWidget(myLabel
);
78 layout
.setContentsMargins(0, 0, 0, 0);
81 QString
LabelEntry::getText()
86 void LabelEntry::label_clicked()
89 if (entry
!= NULL
) return; // events may arrive post-creation
90 entry
= new QLineEdit(this);
91 entry
->setSizePolicy(myLabel
->sizePolicy());
92 // entry->set_activates_default(false);
93 // entry->set_width_chars(15); // FIXME
95 // self-destruct on unfocus or activate
96 connect(entry
, SIGNAL(editingFinished()),
97 this, SLOT(entry_finished()));
99 layout
.removeWidget(myLabel
);
101 layout
.addWidget(entry
);
103 entry
->setFocus(Qt::MouseFocusReason
);
105 void LabelEntry::entry_finished()
107 if (entry
== NULL
) return; // events may arrive post-deletion
109 myLabel
->setText(data
);
110 layout
.removeWidget(entry
);
112 layout
.addWidget(myLabel
);
114 entry
->deleteLater(); // We can now forget about it...
118 void LabelEntry::setAlignment ( Qt::Alignment al
)
120 myLabel
->setAlignment(al
);
122 void LabelEntry::setText ( const QString
& d
)
126 void LabelEntry::setVisible(bool vis
)
128 QWidget::setVisible(vis
);
131 void LabelEntry::setFrameStyle(int i
)
133 myLabel
->setFrameStyle(i
);
135 void LabelEntry::setSizePolicy(QSizePolicy::Policy h
, QSizePolicy::Policy v
)
137 QWidget::setSizePolicy(h
,v
);
138 myLabel
->setSizePolicy(h
,v
);
140 void LabelEntry::setSizePolicy(QSizePolicy p
)
142 QWidget::setSizePolicy(p
);
143 myLabel
->setSizePolicy(p
);
145 void LabelEntry::setFont ( const QFont
& f
)
148 if (entry
) entry
->setFont(f
);
150 QLabel
* LabelEntry::label () { return myLabel
; }