2006-03-05 17:24:44 +00:00
|
|
|
/**
|
2007-04-26 03:53:02 +00:00
|
|
|
* \file LengthCombo.cpp
|
2006-03-05 17:24:44 +00:00
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
*
|
|
|
|
* \author John Levon
|
2009-01-14 10:20:33 +00:00
|
|
|
* \author Jürgen Spitzmüller
|
2008-11-14 15:58:50 +00:00
|
|
|
* \author Herbert Voß
|
2006-03-05 17:24:44 +00:00
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
2009-01-14 10:20:33 +00:00
|
|
|
#include "support/qstring_helpers.h"
|
|
|
|
|
2007-04-26 03:53:02 +00:00
|
|
|
#include "LengthCombo.h"
|
2007-10-24 22:55:02 +00:00
|
|
|
|
2006-12-03 01:11:37 +00:00
|
|
|
#include "qt_helpers.h"
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2009-01-14 10:20:33 +00:00
|
|
|
#include <string>
|
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2012-12-17 20:13:40 +00:00
|
|
|
namespace lyx {
|
|
|
|
namespace frontend {
|
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
LengthCombo::LengthCombo(QWidget * parent)
|
|
|
|
: QComboBox(parent)
|
|
|
|
{
|
2009-01-14 10:20:33 +00:00
|
|
|
for (int i = 0; i < lyx::num_units; i++) {
|
|
|
|
// mu does not make sense usually
|
|
|
|
// so it must be added manually, if needed
|
2010-02-01 01:07:32 +00:00
|
|
|
if (QLatin1String(lyx::unit_name[i]) == "mu")
|
2009-01-14 10:20:33 +00:00
|
|
|
continue;
|
|
|
|
QComboBox::addItem(lyx::qt_(lyx::unit_name_gui[i]),
|
|
|
|
lyx::toqstr(lyx::unit_name[i]));
|
|
|
|
}
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
connect(this, SIGNAL(activated(int)),
|
2009-05-23 09:28:33 +00:00
|
|
|
this, SLOT(hasActivated(int)));
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
|
2007-04-28 12:58:49 +00:00
|
|
|
lyx::Length::UNIT LengthCombo::currentLengthItem() const
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
2009-01-14 10:20:33 +00:00
|
|
|
QString const val = itemData(currentIndex()).toString();
|
|
|
|
return lyx::unitFromString(lyx::fromqstr(val));
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-05-23 09:28:33 +00:00
|
|
|
void LengthCombo::hasActivated(int)
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
2006-10-21 00:16:43 +00:00
|
|
|
// emit signal
|
2006-06-30 14:11:50 +00:00
|
|
|
selectionChanged(currentLengthItem());
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-28 12:58:49 +00:00
|
|
|
void LengthCombo::setCurrentItem(lyx::Length::UNIT unit)
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
2009-01-14 12:57:23 +00:00
|
|
|
setCurrentItem(lyx::toqstr(lyx::stringFromUnit(unit)));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-05-28 20:41:32 +00:00
|
|
|
void LengthCombo::setCurrentItem(QString const & item)
|
2009-01-14 12:57:23 +00:00
|
|
|
{
|
2009-01-14 10:20:33 +00:00
|
|
|
int num = QComboBox::count();
|
|
|
|
for (int i = 0; i < num; i++) {
|
2009-01-14 12:57:23 +00:00
|
|
|
if (QComboBox::itemData(i).toString() == item) {
|
2009-01-14 10:20:33 +00:00
|
|
|
QComboBox::setCurrentIndex(i);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void LengthCombo::setCurrentItem(int item)
|
|
|
|
{
|
2006-08-17 08:49:57 +00:00
|
|
|
QComboBox::setCurrentIndex(item);
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void LengthCombo::setEnabled(bool b)
|
|
|
|
{
|
|
|
|
QComboBox::setEnabled(b);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void LengthCombo::noPercents()
|
|
|
|
{
|
|
|
|
int num = QComboBox::count();
|
|
|
|
for (int i = 0; i < num; i++) {
|
2009-01-14 10:20:33 +00:00
|
|
|
if (QComboBox::itemData(i).toString().contains('%')) {
|
2006-03-05 17:24:44 +00:00
|
|
|
QComboBox::removeItem(i);
|
2006-10-21 00:16:43 +00:00
|
|
|
--i;
|
|
|
|
--num;
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2006-05-18 08:51:12 +00:00
|
|
|
|
2009-01-14 10:20:33 +00:00
|
|
|
|
2015-07-18 14:41:52 +00:00
|
|
|
void LengthCombo::removeFontDependent()
|
|
|
|
{
|
|
|
|
removeUnit(Length::EM);
|
|
|
|
removeUnit(Length::EX);
|
|
|
|
removeUnit(Length::MU);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-01-14 12:57:23 +00:00
|
|
|
void LengthCombo::removeUnit(lyx::Length::UNIT unit)
|
2009-01-14 10:20:33 +00:00
|
|
|
{
|
|
|
|
QString const val = lyx::toqstr(lyx::stringFromUnit(unit));
|
|
|
|
int num = QComboBox::count();
|
|
|
|
for (int i = 0; i < num; i++) {
|
|
|
|
if (QComboBox::itemData(i).toString() == val) {
|
|
|
|
QComboBox::removeItem(i);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-01-14 12:57:23 +00:00
|
|
|
void LengthCombo::addUnit(lyx::Length::UNIT unit)
|
2009-01-14 10:20:33 +00:00
|
|
|
{
|
|
|
|
QString const val = lyx::toqstr(lyx::stringFromUnit(unit));
|
|
|
|
int num = QComboBox::count();
|
|
|
|
for (int i = 0; i < num; i++) {
|
|
|
|
if (QComboBox::itemData(i).toString() == val) {
|
|
|
|
// already there, nothing to do
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
insertItem(int(unit), lyx::qt_(lyx::unit_name_gui[int(unit)]),
|
|
|
|
lyx::toqstr(lyx::unit_name[int(unit)]));
|
|
|
|
}
|
|
|
|
|
2012-12-17 20:13:40 +00:00
|
|
|
} // namespace frontend
|
|
|
|
} // namespace lyx
|
2009-01-14 10:20:33 +00:00
|
|
|
|
2008-11-14 14:28:50 +00:00
|
|
|
#include "moc_LengthCombo.cpp"
|