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"
26 // SLabel a label that emits pressed() when clicked
27 SLabel::SLabel(QWidget
* parent
, Qt::WindowFlags f
) :
31 SLabel::SLabel( const QString
& text
, QWidget
* parent
, Qt::WindowFlags f
) :
32 QLabel(text
, parent
, f
)
35 void SLabel::setVisible(bool vis
)
38 QLabel::setVisible(vis
);
40 void SLabel::mousePressEvent ( QMouseEvent
* event
)
42 if (event
->button() == Qt::LeftButton
) emit
pressed();
45 // LabelEntry - a label that turns into a textbox when clicked
46 LabelEntry::LabelEntry(QWidget
*parent
) :
54 LabelEntry::LabelEntry(const QString
& value
, QWidget
*parent
) :
62 void LabelEntry::init()
64 label
= new SLabel(data
, this);
65 connect(label
, SIGNAL(pressed()),
66 this, SLOT(label_clicked()));
67 layout
.addWidget(label
);
68 layout
.setContentsMargins(0, 0, 0, 0);
71 QString
LabelEntry::getText()
76 void LabelEntry::label_clicked()
79 if (entry
!= NULL
) return; // events may arrive post-creation
80 entry
= new QLineEdit(this);
81 entry
->setSizePolicy(label
->sizePolicy());
82 // entry->set_activates_default(false);
83 // entry->set_width_chars(15); // FIXME
85 // self-destruct on unfocus or activate
86 connect(entry
, SIGNAL(editingFinished()),
87 this, SLOT(entry_finished()));
89 layout
.removeWidget(label
);
91 layout
.addWidget(entry
);
93 entry
->setFocus(Qt::MouseFocusReason
);
95 void LabelEntry::entry_finished()
98 if (entry
== NULL
) return; // events may arrive post-deletion
100 label
->setText(data
);
101 layout
.removeWidget(entry
);
103 layout
.addWidget(label
);
105 entry
->deleteLater(); // We can now forget about it...
109 void LabelEntry::setAlignment ( Qt::Alignment al
)
111 label
->setAlignment(al
);
113 void LabelEntry::setText ( const QString
& d
)
117 void LabelEntry::setVisible(bool vis
)
120 QWidget::setVisible(vis
);
123 void LabelEntry::setFrameStyle(int i
)
125 label
->setFrameStyle(i
);
127 void LabelEntry::setSizePolicy(QSizePolicy::Policy h
, QSizePolicy::Policy v
)
129 QWidget::setSizePolicy(h
,v
);
130 label
->setSizePolicy(h
,v
);
132 void LabelEntry::setSizePolicy(QSizePolicy p
)
135 QWidget::setSizePolicy(p
);
136 label
->setSizePolicy(p
);