2006-03-05 17:24:44 +00:00
|
|
|
|
/**
|
2007-04-26 03:53:02 +00:00
|
|
|
|
* \file qt_helpers.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 Dekel Tsur
|
|
|
|
|
* \author J<EFBFBD>rgen Spitzm<EFBFBD>ller
|
2007-04-05 14:58:15 +00:00
|
|
|
|
* \author Richard Heck
|
2006-03-05 17:24:44 +00:00
|
|
|
|
*
|
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
2007-04-26 03:53:02 +00:00
|
|
|
|
#include "LengthCombo.h"
|
2006-03-05 17:24:44 +00:00
|
|
|
|
#include "qt_helpers.h"
|
|
|
|
|
|
|
|
|
|
#include "lengthcommon.h"
|
|
|
|
|
#include "gettext.h"
|
|
|
|
|
|
2007-01-18 12:30:07 +00:00
|
|
|
|
#include "support/os.h"
|
2006-03-05 17:24:44 +00:00
|
|
|
|
#include "support/lstrings.h"
|
|
|
|
|
|
2006-08-30 14:59:07 +00:00
|
|
|
|
#include "debug.h"
|
|
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
|
#include <QComboBox>
|
2007-04-05 14:58:15 +00:00
|
|
|
|
#include <QCheckBox>
|
2007-09-15 13:06:48 +00:00
|
|
|
|
#include <QPalette>
|
2007-09-15 15:42:22 +00:00
|
|
|
|
#include <QLineEdit>
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
|
|
#include <algorithm>
|
|
|
|
|
|
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
|
namespace lyx {
|
|
|
|
|
|
Make libQtCore a support library like boost and implement encoding conversion
from/to the local 8bit encoding with it.
Only the autotools build system is updated, scons and cmake users need to
add qt4 cpp flags when compiling libsupport, and link libsupport against
libQtCore.
* src/frontends/qt4/qt_helpers.[Ch]
(toqstr, qchar_to_ucs4, ucs4_to_qchar, ucs4_to_qstring,
qstring_to_ucs4, fromqstr): Move these qstring conversion functions
from here ...
* src/support/qstring_helpers.[Ch] ... to these new files
* src/support/docstring.[Ch]
(from_local8bit): new conversion function from local 8bit encoding
to ucs4
(to_local8bit): new conversion function from ucs4 to local 8bit
encoding to ucs4
(to_local8bit_failure): exception that is thrown by to_local8bit if
the argument cannot be converted to the local encoding
* src/support/filename.C
(FileName::toFilesystemEncoding): implement with the help of QFile
* src/support/Makefile.am: Add new files, qt4 cpp flags and link
against libQtCore
* src/client/client.C: Convert commandline input from local encoding
to ucs4. Convert stuff that is sent to to the server to utf8,
because LyX interprets it as utf8 on the other end of the pipe.
* src/lyx_main.C
(LyX::exec): convert commandline input from local encoding to utf8
(LyX::init): ditto
(LyX::easyParse): ditto
* development/scons/scons_manifest.py: Add new files
* config/qt4.m4: Define new variables QT4_CORE_INCLUDES,
QT4_CORE_LDFLAGS and QT4_CORE_LIB
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@16257 a592a061-630c-0410-9148-cb99ea01b6c8
2006-12-12 20:19:46 +00:00
|
|
|
|
using support::isStrDbl;
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
2006-08-30 14:59:07 +00:00
|
|
|
|
using std::vector;
|
2006-03-05 17:24:44 +00:00
|
|
|
|
using std::string;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
string widgetsToLength(QLineEdit const * input, LengthCombo const * combo)
|
|
|
|
|
{
|
2006-09-09 22:27:22 +00:00
|
|
|
|
QString const length = input->text();
|
2006-03-05 17:24:44 +00:00
|
|
|
|
if (length.isEmpty())
|
|
|
|
|
return string();
|
|
|
|
|
|
2006-09-09 22:27:22 +00:00
|
|
|
|
// Don't return unit-from-choice if the input(field) contains a unit
|
2006-03-05 17:24:44 +00:00
|
|
|
|
if (isValidGlueLength(fromqstr(length)))
|
|
|
|
|
return fromqstr(length);
|
|
|
|
|
|
2007-04-28 12:58:49 +00:00
|
|
|
|
Length::UNIT const unit = combo->currentLengthItem();
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
2007-04-28 12:58:49 +00:00
|
|
|
|
return Length(length.toDouble(), unit).asString();
|
2006-03-05 17:24:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-04-28 12:58:49 +00:00
|
|
|
|
Length widgetsToLength(QLineEdit const * input, QComboBox const * combo)
|
2006-03-05 17:24:44 +00:00
|
|
|
|
{
|
2006-09-09 22:27:22 +00:00
|
|
|
|
QString const length = input->text();
|
2006-03-05 17:24:44 +00:00
|
|
|
|
if (length.isEmpty())
|
2007-04-28 12:58:49 +00:00
|
|
|
|
return Length();
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
|
|
// don't return unit-from-choice if the input(field) contains a unit
|
|
|
|
|
if (isValidGlueLength(fromqstr(length)))
|
2007-04-28 12:58:49 +00:00
|
|
|
|
return Length(fromqstr(length));
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
2007-04-28 12:58:49 +00:00
|
|
|
|
Length::UNIT const unit = unitFromString(fromqstr(combo->currentText()));
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
2007-04-28 12:58:49 +00:00
|
|
|
|
return Length(length.toDouble(), unit);
|
2006-03-05 17:24:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-04-05 14:58:15 +00:00
|
|
|
|
void lengthToWidgets(QLineEdit * input, LengthCombo * combo,
|
2007-08-10 20:14:54 +00:00
|
|
|
|
Length const & len, Length::UNIT /*defaultUnit*/)
|
2007-04-05 14:58:15 +00:00
|
|
|
|
{
|
2007-09-15 15:42:22 +00:00
|
|
|
|
combo->setCurrentItem(len.unit());
|
2007-09-11 21:27:57 +00:00
|
|
|
|
input->setText(QString::number(Length(len).value()));
|
2007-04-05 14:58:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
|
void lengthToWidgets(QLineEdit * input, LengthCombo * combo,
|
2007-04-28 12:58:49 +00:00
|
|
|
|
string const & len, Length::UNIT defaultUnit)
|
2006-03-05 17:24:44 +00:00
|
|
|
|
{
|
|
|
|
|
if (len.empty()) {
|
|
|
|
|
// no length (UNIT_NONE)
|
|
|
|
|
combo->setCurrentItem(defaultUnit);
|
|
|
|
|
input->setText("");
|
|
|
|
|
} else if (!isValidLength(len) && !isStrDbl(len)) {
|
|
|
|
|
// use input field only for gluelengths
|
|
|
|
|
combo->setCurrentItem(defaultUnit);
|
|
|
|
|
input->setText(toqstr(len));
|
|
|
|
|
} else {
|
2007-04-28 12:58:49 +00:00
|
|
|
|
lengthToWidgets(input, combo, Length(len), defaultUnit);
|
2006-03-05 17:24:44 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-05-28 22:27:45 +00:00
|
|
|
|
void lengthAutoToWidgets(QLineEdit * input, LengthCombo * combo,
|
2007-04-28 12:58:49 +00:00
|
|
|
|
Length const & len, Length::UNIT defaultUnit)
|
2007-04-05 14:58:15 +00:00
|
|
|
|
{
|
2007-05-28 22:27:45 +00:00
|
|
|
|
if (len.value() == 0)
|
2007-04-05 14:58:15 +00:00
|
|
|
|
lengthToWidgets(input, combo, "auto", defaultUnit);
|
|
|
|
|
else
|
|
|
|
|
lengthToWidgets(input, combo, len, defaultUnit);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//NOTE "CB" here because we probably will want one of these
|
|
|
|
|
//for labeled sets, as well.
|
2007-05-28 22:27:45 +00:00
|
|
|
|
void setAutoTextCB(QCheckBox * checkBox, QLineEdit * lineEdit,
|
|
|
|
|
LengthCombo * lengthCombo)
|
2007-04-05 14:58:15 +00:00
|
|
|
|
{
|
2007-05-28 22:27:45 +00:00
|
|
|
|
if (!checkBox->isChecked())
|
2007-04-25 16:39:21 +00:00
|
|
|
|
lengthToWidgets(lineEdit, lengthCombo,
|
2007-05-28 22:27:45 +00:00
|
|
|
|
"auto", lengthCombo->currentLengthItem());
|
2007-04-05 14:58:15 +00:00
|
|
|
|
else if (lineEdit->text() == "auto")
|
2007-04-25 16:39:21 +00:00
|
|
|
|
lengthToWidgets(lineEdit, lengthCombo, string(),
|
2007-05-28 22:27:45 +00:00
|
|
|
|
lengthCombo->currentLengthItem());
|
2007-04-05 14:58:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-09-15 13:06:48 +00:00
|
|
|
|
void setValid(QWidget * widget, bool valid)
|
|
|
|
|
{
|
|
|
|
|
if (valid) {
|
|
|
|
|
widget->setPalette(QPalette());
|
|
|
|
|
} else {
|
|
|
|
|
QPalette pal = widget->palette();
|
|
|
|
|
pal.setColor(QPalette::Active, QPalette::Foreground, QColor(255, 0, 0));
|
|
|
|
|
widget->setPalette(pal);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-11-07 18:09:55 +00:00
|
|
|
|
QString const qt_(char const * str, const char *)
|
2006-03-05 17:24:44 +00:00
|
|
|
|
{
|
2006-09-09 22:27:22 +00:00
|
|
|
|
return toqstr(_(str));
|
2006-03-05 17:24:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QString const qt_(string const & str)
|
|
|
|
|
{
|
2006-09-09 22:27:22 +00:00
|
|
|
|
return toqstr(_(str));
|
2006-03-05 17:24:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
|
} // namespace lyx
|