mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-22 21:21:32 +00:00
shuffle stuff around; minor coding style issues
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@20289 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
f53592dd60
commit
6c26624d39
@ -38,7 +38,7 @@
|
||||
#endif
|
||||
|
||||
#ifdef USE_NATIVE_FILEDIALOG
|
||||
#include <qapplication.h>
|
||||
#include <QApplication>
|
||||
#include "support/filetools.h"
|
||||
|
||||
using lyx::support::makeAbsPath;
|
||||
|
@ -235,6 +235,15 @@ void GuiFontLoader::update()
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
|
||||
static QString makeFontName(string const & family, string const & foundry)
|
||||
{
|
||||
QString res = toqstr(family);
|
||||
if (!foundry.empty())
|
||||
res += " [" + toqstr(foundry) + ']';
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
QLFontInfo::QLFontInfo(Font const & f)
|
||||
{
|
||||
font.setKerning(false);
|
||||
@ -245,8 +254,8 @@ QLFontInfo::QLFontInfo(Font const & f)
|
||||
} else {
|
||||
switch (f.family()) {
|
||||
case Font::ROMAN_FAMILY: {
|
||||
QString family = toqstr(makeFontName(lyxrc.roman_font_name,
|
||||
lyxrc.roman_font_foundry));
|
||||
QString family = makeFontName(lyxrc.roman_font_name,
|
||||
lyxrc.roman_font_foundry);
|
||||
font.setFamily(family);
|
||||
#ifdef Q_WS_MACX
|
||||
#if QT_VERSION >= 0x040300
|
||||
@ -260,12 +269,12 @@ QLFontInfo::QLFontInfo(Font const & f)
|
||||
break;
|
||||
}
|
||||
case Font::SANS_FAMILY:
|
||||
font.setFamily(toqstr(makeFontName(lyxrc.sans_font_name,
|
||||
lyxrc.sans_font_foundry)));
|
||||
font.setFamily(makeFontName(lyxrc.sans_font_name,
|
||||
lyxrc.sans_font_foundry));
|
||||
break;
|
||||
case Font::TYPEWRITER_FAMILY:
|
||||
font.setFamily(toqstr(makeFontName(lyxrc.typewriter_font_name,
|
||||
lyxrc.typewriter_font_foundry)));
|
||||
font.setFamily(makeFontName(lyxrc.typewriter_font_name,
|
||||
lyxrc.typewriter_font_foundry));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
@ -41,6 +41,7 @@
|
||||
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
#include <utility>
|
||||
|
||||
using lyx::support::float_equal;
|
||||
using lyx::support::token;
|
||||
@ -59,6 +60,34 @@ namespace lyx {
|
||||
namespace frontend {
|
||||
|
||||
|
||||
//FIXME setAutoTextCB should really take an argument, as indicated, that
|
||||
//determines what text is to be written for "auto". But making
|
||||
//that work involves more extensive revisions than we now want
|
||||
//to make, since "auto" also appears in updateContents() (see
|
||||
//GuiGraphics.cpp).
|
||||
//The right way to do this, I think, would be to define a class
|
||||
//checkedLengthSet (and a partnering labeledLengthSete) that encapsulated
|
||||
//the checkbox, line edit, and length combo together, and then made e.g.
|
||||
//lengthToWidgets, widgetsToLength, etc, all public methods of that class.
|
||||
//Perhaps even the validator could be exposed through it.
|
||||
/**
|
||||
* sets a checkbox-line edit-length combo group, using "text" if the
|
||||
* checkbox is unchecked and clearing the line edit if it previously
|
||||
* said "text".
|
||||
*/
|
||||
void setAutoTextCB(QCheckBox * checkBox, QLineEdit * lineEdit,
|
||||
LengthCombo * lengthCombo/*, string text = "auto"*/)
|
||||
{
|
||||
if (!checkBox->isChecked())
|
||||
lengthToWidgets(lineEdit, lengthCombo,
|
||||
"auto", lengthCombo->currentLengthItem());
|
||||
else if (lineEdit->text() == "auto")
|
||||
lengthToWidgets(lineEdit, lengthCombo, string(),
|
||||
lengthCombo->currentLengthItem());
|
||||
}
|
||||
|
||||
|
||||
|
||||
template<class Pair>
|
||||
std::vector<typename Pair::first_type> const
|
||||
getFirst(std::vector<Pair> const & pr)
|
||||
|
@ -46,6 +46,7 @@
|
||||
#include <iomanip>
|
||||
#include <sstream>
|
||||
#include <algorithm>
|
||||
#include <utility>
|
||||
|
||||
using namespace Ui;
|
||||
|
||||
@ -82,12 +83,25 @@ static size_t findPos_helper(std::vector<A> const & vec, A const & val)
|
||||
}
|
||||
|
||||
|
||||
static std::pair<string, string> parseFontName(string const & name)
|
||||
{
|
||||
string::size_type const idx = name.find('[');
|
||||
if (idx == string::npos || idx == 0)
|
||||
return make_pair(name, string());
|
||||
return make_pair(name.substr(0, idx - 1),
|
||||
name.substr(idx + 1, name.size() - idx - 2));
|
||||
}
|
||||
|
||||
|
||||
static void setComboxFont(QComboBox * cb, string const & family,
|
||||
string const & foundry)
|
||||
{
|
||||
string const name = makeFontName(family, foundry);
|
||||
QString fontname = toqstr(family);
|
||||
if (!foundry.empty())
|
||||
fontname += " [" + toqstr(foundry) + ']';
|
||||
|
||||
for (int i = 0; i < cb->count(); ++i) {
|
||||
if (fromqstr(cb->itemText(i)) == name) {
|
||||
if (cb->itemText(i) == fontname) {
|
||||
cb->setCurrentIndex(i);
|
||||
return;
|
||||
}
|
||||
@ -96,7 +110,7 @@ static void setComboxFont(QComboBox * cb, string const & family,
|
||||
// Try matching without foundry name
|
||||
|
||||
// We count in reverse in order to prefer the Xft foundry
|
||||
for (int i = cb->count() - 1; i >= 0; --i) {
|
||||
for (int i = cb->count(); --i >= 0;) {
|
||||
pair<string, string> tmp = parseFontName(fromqstr(cb->itemText(i)));
|
||||
if (compare_ascii_no_case(tmp.first, family) == 0) {
|
||||
cb->setCurrentIndex(i);
|
||||
@ -317,7 +331,6 @@ PrefLatex::PrefLatex(GuiPrefsDialog * form, QWidget * parent)
|
||||
#else
|
||||
pathCB->setVisible(false);
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -409,26 +422,16 @@ PrefScreenFonts::PrefScreenFonts(GuiPrefsDialog * form, QWidget * parent)
|
||||
connect(screenHugerED, SIGNAL(textChanged(const QString&)),
|
||||
this, SIGNAL(changed()));
|
||||
|
||||
screenTinyED->setValidator(new QDoubleValidator(
|
||||
screenTinyED));
|
||||
screenSmallestED->setValidator(new QDoubleValidator(
|
||||
screenSmallestED));
|
||||
screenSmallerED->setValidator(new QDoubleValidator(
|
||||
screenSmallerED));
|
||||
screenSmallED->setValidator(new QDoubleValidator(
|
||||
screenSmallED));
|
||||
screenNormalED->setValidator(new QDoubleValidator(
|
||||
screenNormalED));
|
||||
screenLargeED->setValidator(new QDoubleValidator(
|
||||
screenLargeED));
|
||||
screenLargerED->setValidator(new QDoubleValidator(
|
||||
screenLargerED));
|
||||
screenLargestED->setValidator(new QDoubleValidator(
|
||||
screenLargestED));
|
||||
screenHugeED->setValidator(new QDoubleValidator(
|
||||
screenHugeED));
|
||||
screenHugerED->setValidator(new QDoubleValidator(
|
||||
screenHugerED));
|
||||
screenTinyED->setValidator(new QDoubleValidator(screenTinyED));
|
||||
screenSmallestED->setValidator(new QDoubleValidator(screenSmallestED));
|
||||
screenSmallerED->setValidator(new QDoubleValidator(screenSmallerED));
|
||||
screenSmallED->setValidator(new QDoubleValidator(screenSmallED));
|
||||
screenNormalED->setValidator(new QDoubleValidator(screenNormalED));
|
||||
screenLargeED->setValidator(new QDoubleValidator(screenLargeED));
|
||||
screenLargerED->setValidator(new QDoubleValidator(screenLargerED));
|
||||
screenLargestED->setValidator(new QDoubleValidator(screenLargestED));
|
||||
screenHugeED->setValidator(new QDoubleValidator(screenHugeED));
|
||||
screenHugerED->setValidator(new QDoubleValidator(screenHugerED));
|
||||
}
|
||||
|
||||
|
||||
@ -575,11 +578,9 @@ PrefColors::PrefColors(GuiPrefsDialog * form, QWidget * parent)
|
||||
|
||||
void PrefColors::apply(LyXRC & /*rc*/) const
|
||||
{
|
||||
for (unsigned int i = 0; i < lcolors_.size(); ++i) {
|
||||
if (curcolors_[i] != newcolors_[i]) {
|
||||
for (unsigned int i = 0; i < lcolors_.size(); ++i)
|
||||
if (curcolors_[i] != newcolors_[i])
|
||||
form_->controller().setColor(lcolors_[i], fromqstr(newcolors_[i]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -600,10 +601,11 @@ void PrefColors::change_color()
|
||||
int const row = lyxObjectsLW->currentRow();
|
||||
|
||||
// just to be sure
|
||||
if (row < 0) return;
|
||||
if (row < 0)
|
||||
return;
|
||||
|
||||
QString const color = newcolors_[row];
|
||||
QColor c(QColorDialog::getColor(QColor(color), qApp->focusWidget()));
|
||||
QColor c = QColorDialog::getColor(QColor(color), qApp->focusWidget());
|
||||
|
||||
if (c.isValid() && c.name() != color) {
|
||||
newcolors_[row] = c.name();
|
||||
@ -641,18 +643,18 @@ PrefDisplay::PrefDisplay(QWidget * parent)
|
||||
void PrefDisplay::apply(LyXRC & rc) const
|
||||
{
|
||||
switch (instantPreviewCO->currentIndex()) {
|
||||
case 0: rc.preview = LyXRC::PREVIEW_OFF; break;
|
||||
case 1: rc.preview = LyXRC::PREVIEW_NO_MATH; break;
|
||||
case 2: rc.preview = LyXRC::PREVIEW_ON; break;
|
||||
case 0: rc.preview = LyXRC::PREVIEW_OFF; break;
|
||||
case 1: rc.preview = LyXRC::PREVIEW_NO_MATH; break;
|
||||
case 2: rc.preview = LyXRC::PREVIEW_ON; break;
|
||||
}
|
||||
|
||||
lyx::graphics::DisplayType dtype;
|
||||
switch (displayGraphicsCO->currentIndex()) {
|
||||
case 3: dtype = lyx::graphics::NoDisplay; break;
|
||||
case 2: dtype = lyx::graphics::ColorDisplay; break;
|
||||
case 1: dtype = lyx::graphics::GrayscaleDisplay; break;
|
||||
case 0: dtype = lyx::graphics::MonochromeDisplay; break;
|
||||
default: dtype = lyx::graphics::GrayscaleDisplay;
|
||||
case 3: dtype = lyx::graphics::NoDisplay; break;
|
||||
case 2: dtype = lyx::graphics::ColorDisplay; break;
|
||||
case 1: dtype = lyx::graphics::GrayscaleDisplay; break;
|
||||
case 0: dtype = lyx::graphics::MonochromeDisplay; break;
|
||||
default: dtype = lyx::graphics::GrayscaleDisplay;
|
||||
}
|
||||
rc.display_graphics = dtype;
|
||||
|
||||
@ -1000,7 +1002,7 @@ void PrefConverters::updateGui()
|
||||
if (!current.isEmpty()) {
|
||||
QList<QListWidgetItem *> const item =
|
||||
convertersLW->findItems(current, Qt::MatchExactly);
|
||||
if (item.size()>0)
|
||||
if (!item.isEmpty())
|
||||
convertersLW->setCurrentItem(item.at(0));
|
||||
}
|
||||
|
||||
@ -1063,16 +1065,17 @@ void PrefConverters::updateButtons()
|
||||
// this is why we can use the same function for both new and modify
|
||||
void PrefConverters::update_converter()
|
||||
{
|
||||
Format const & from(form_->formats().get(converterFromCO->currentIndex()));
|
||||
Format const & to(form_->formats().get(converterToCO->currentIndex()));
|
||||
Format const & from = form_->formats().get(converterFromCO->currentIndex());
|
||||
Format const & to = form_->formats().get(converterToCO->currentIndex());
|
||||
string const flags = fromqstr(converterFlagED->text());
|
||||
string const command = fromqstr(converterED->text());
|
||||
|
||||
Converter const * old = form_->converters().getConverter(from.name(), to.name());
|
||||
Converter const * old =
|
||||
form_->converters().getConverter(from.name(), to.name());
|
||||
form_->converters().add(from.name(), to.name(), command, flags);
|
||||
if (!old) {
|
||||
|
||||
if (!old)
|
||||
form_->converters().updateLast(form_->formats());
|
||||
}
|
||||
|
||||
updateGui();
|
||||
|
||||
@ -1084,8 +1087,8 @@ void PrefConverters::update_converter()
|
||||
|
||||
void PrefConverters::remove_converter()
|
||||
{
|
||||
Format const & from(form_->formats().get(converterFromCO->currentIndex()));
|
||||
Format const & to(form_->formats().get(converterToCO->currentIndex()));
|
||||
Format const & from = form_->formats().get(converterFromCO->currentIndex());
|
||||
Format const & to = form_->formats().get(converterToCO->currentIndex());
|
||||
form_->converters().erase(from.name(), to.name());
|
||||
|
||||
updateGui();
|
||||
@ -1481,34 +1484,37 @@ void PrefFileformats::updateButtons()
|
||||
}
|
||||
|
||||
// assure that a gui name cannot be chosen twice
|
||||
bool const known_otherwise = gui_name_known && (where != sel);
|
||||
bool const known_otherwise = gui_name_known && where != sel;
|
||||
|
||||
bool const known = !(sel < 0);
|
||||
bool const valid = (!formatED->text().isEmpty()
|
||||
&& !guiNameED->text().isEmpty());
|
||||
bool const known = sel >= 0;
|
||||
bool const valid = !formatED->text().isEmpty()
|
||||
&& !guiNameED->text().isEmpty();
|
||||
|
||||
int const ftype = formatsLW->currentItem()->type();
|
||||
Format const & f(form_->formats().get(ftype));
|
||||
string const old_pretty(f.prettyname());
|
||||
string const old_shortcut(f.shortcut());
|
||||
string const old_extension(f.extension());
|
||||
string const old_viewer(f.viewer());
|
||||
string const old_editor(f.editor());
|
||||
bool const old_document(f.documentFormat());
|
||||
bool const old_vector(f.vectorFormat());
|
||||
Format const & f = form_->formats().get(ftype);
|
||||
string const old_pretty = f.prettyname();
|
||||
string const old_shortcut = f.shortcut();
|
||||
string const old_extension = f.extension();
|
||||
string const old_viewer = f.viewer();
|
||||
string const old_editor = f.editor();
|
||||
bool const old_document = f.documentFormat();
|
||||
bool const old_vector = f.vectorFormat();
|
||||
|
||||
string const new_pretty(fromqstr(gui_name));
|
||||
string const new_shortcut(fromqstr(shortcutED->text()));
|
||||
string const new_extension(fromqstr(extensionED->text()));
|
||||
string const new_viewer(fromqstr(viewerED->text()));
|
||||
string const new_editor(fromqstr(editorED->text()));
|
||||
bool const new_document(documentCB->isChecked());
|
||||
bool const new_vector(vectorCB->isChecked());
|
||||
string const new_pretty = fromqstr(gui_name);
|
||||
string const new_shortcut = fromqstr(shortcutED->text());
|
||||
string const new_extension = fromqstr(extensionED->text());
|
||||
string const new_viewer = fromqstr(viewerED->text());
|
||||
string const new_editor = fromqstr(editorED->text());
|
||||
bool const new_document = documentCB->isChecked();
|
||||
bool const new_vector = vectorCB->isChecked();
|
||||
|
||||
bool modified = ((old_pretty != new_pretty) || (old_shortcut != new_shortcut)
|
||||
|| (old_extension != new_extension) || (old_viewer != new_viewer)
|
||||
|| old_editor != new_editor || old_document != new_document
|
||||
|| old_vector != new_vector);
|
||||
bool modified = old_pretty != new_pretty
|
||||
|| old_shortcut != new_shortcut
|
||||
|| old_extension != new_extension
|
||||
|| old_viewer != new_viewer
|
||||
|| old_editor != new_editor
|
||||
|| old_document != new_document
|
||||
|| old_vector != new_vector;
|
||||
|
||||
formatModifyPB->setEnabled(valid && known && modified && !known_otherwise);
|
||||
formatNewPB->setEnabled(valid && !known && !gui_name_known);
|
||||
@ -1843,12 +1849,11 @@ void PrefUserInterface::update(LyXRC const & rc)
|
||||
}
|
||||
|
||||
|
||||
|
||||
void PrefUserInterface::select_ui()
|
||||
{
|
||||
docstring const name =
|
||||
from_utf8(internal_path(fromqstr(uiFileED->text())));
|
||||
docstring file(form_->controller().browseUI(name));
|
||||
docstring file = form_->controller().browseUI(name);
|
||||
if (!file.empty())
|
||||
uiFileED->setText(toqstr(file));
|
||||
}
|
||||
@ -1858,7 +1863,7 @@ void PrefUserInterface::select_bind()
|
||||
{
|
||||
docstring const name =
|
||||
from_utf8(internal_path(fromqstr(bindFileED->text())));
|
||||
docstring file(form_->controller().browsebind(name));
|
||||
docstring file = form_->controller().browsebind(name);
|
||||
if (!file.empty())
|
||||
bindFileED->setText(toqstr(file));
|
||||
}
|
||||
@ -1874,7 +1879,7 @@ void PrefUserInterface::on_loadWindowSizeCB_toggled(bool loadwindowsize)
|
||||
|
||||
|
||||
PrefIdentity::PrefIdentity(QWidget * parent)
|
||||
: PrefModule(_("Identity"), 0, parent)
|
||||
: PrefModule(_("Identity"), 0, parent)
|
||||
{
|
||||
setupUi(this);
|
||||
|
||||
@ -2012,16 +2017,19 @@ Converters & GuiPrefsDialog::converters()
|
||||
return controller().converters();
|
||||
}
|
||||
|
||||
|
||||
Formats & GuiPrefsDialog::formats()
|
||||
{
|
||||
return controller().formats();
|
||||
}
|
||||
|
||||
|
||||
Movers & GuiPrefsDialog::movers()
|
||||
{
|
||||
return controller().movers();
|
||||
}
|
||||
|
||||
|
||||
void GuiPrefsDialog::applyView()
|
||||
{
|
||||
apply(controller().rc());
|
||||
|
@ -36,19 +36,64 @@ using lyx::support::bformat;
|
||||
|
||||
namespace lyx {
|
||||
|
||||
namespace {
|
||||
|
||||
class MessageBox: public QMessageBox
|
||||
static docstring const formatted(docstring const & text)
|
||||
{
|
||||
public:
|
||||
MessageBox(QWidget * parent = 0) : QMessageBox(parent)
|
||||
{
|
||||
setAttribute(Qt::WA_DeleteOnClose, true);
|
||||
setAttribute(Qt::WA_QuitOnClose, false);
|
||||
}
|
||||
};
|
||||
const int w = 80;
|
||||
docstring sout;
|
||||
|
||||
} // anonymous namespace
|
||||
if (text.empty())
|
||||
return sout;
|
||||
|
||||
docstring::size_type curpos = 0;
|
||||
docstring line;
|
||||
|
||||
for (;;) {
|
||||
docstring::size_type const nxtpos1 = text.find(' ', curpos);
|
||||
docstring::size_type const nxtpos2 = text.find('\n', curpos);
|
||||
docstring::size_type const nxtpos = std::min(nxtpos1, nxtpos2);
|
||||
|
||||
docstring const word =
|
||||
nxtpos == docstring::npos ?
|
||||
text.substr(curpos) :
|
||||
text.substr(curpos, nxtpos - curpos);
|
||||
|
||||
bool const newline = (nxtpos2 != docstring::npos &&
|
||||
nxtpos2 < nxtpos1);
|
||||
|
||||
docstring const line_plus_word =
|
||||
line.empty() ? word : line + char_type(' ') + word;
|
||||
|
||||
// FIXME: make w be size_t
|
||||
if (int(line_plus_word.length()) >= w) {
|
||||
sout += line + char_type('\n');
|
||||
if (newline) {
|
||||
sout += word + char_type('\n');
|
||||
line.erase();
|
||||
} else {
|
||||
line = word;
|
||||
}
|
||||
|
||||
} else if (newline) {
|
||||
sout += line_plus_word + char_type('\n');
|
||||
line.erase();
|
||||
|
||||
} else {
|
||||
if (!line.empty())
|
||||
line += char_type(' ');
|
||||
line += word;
|
||||
}
|
||||
|
||||
if (nxtpos == docstring::npos) {
|
||||
if (!line.empty())
|
||||
sout += line;
|
||||
break;
|
||||
}
|
||||
|
||||
curpos = nxtpos + 1;
|
||||
}
|
||||
|
||||
return sout;
|
||||
}
|
||||
|
||||
|
||||
int prompt_pimpl(docstring const & tit, docstring const & question,
|
||||
@ -57,7 +102,7 @@ int prompt_pimpl(docstring const & tit, docstring const & question,
|
||||
{
|
||||
docstring const title = bformat(_("LyX: %1$s"), tit);
|
||||
|
||||
MessageBox mb;
|
||||
QMessageBox mb;
|
||||
|
||||
// For some reason, sometimes Qt uses an hourglass or watch cursor when
|
||||
// displaying the alert. Hence, we ask for the standard cursor shape.
|
||||
@ -65,7 +110,7 @@ int prompt_pimpl(docstring const & tit, docstring const & question,
|
||||
qApp->changeOverrideCursor(Qt::ArrowCursor);
|
||||
|
||||
// FIXME replace that with theApp->gui()->currentView()
|
||||
int res = mb.information(qApp->focusWidget(),
|
||||
int res = QMessageBox::information(qApp->focusWidget(),
|
||||
toqstr(title),
|
||||
toqstr(formatted(question)),
|
||||
toqstr(b1),
|
||||
@ -93,8 +138,7 @@ void warning_pimpl(docstring const & tit, docstring const & message)
|
||||
toqstr(formatted(message)));
|
||||
return;
|
||||
}
|
||||
MessageBox mb;
|
||||
mb.warning(qApp->focusWidget(),
|
||||
QMessageBox::warning(qApp->focusWidget(),
|
||||
toqstr(title),
|
||||
toqstr(formatted(message)));
|
||||
}
|
||||
@ -112,8 +156,7 @@ void error_pimpl(docstring const & tit, docstring const & message)
|
||||
toqstr(formatted(message)));
|
||||
return;
|
||||
}
|
||||
MessageBox mb;
|
||||
mb.critical(qApp->focusWidget(),
|
||||
QMessageBox::critical(qApp->focusWidget(),
|
||||
toqstr(title),
|
||||
toqstr(formatted(message)));
|
||||
}
|
||||
@ -122,8 +165,7 @@ void error_pimpl(docstring const & tit, docstring const & message)
|
||||
void information_pimpl(docstring const & tit, docstring const & message)
|
||||
{
|
||||
docstring const title = bformat(_("LyX: %1$s"), tit);
|
||||
MessageBox mb;
|
||||
mb.information(qApp->focusWidget(),
|
||||
QMessageBox::information(qApp->focusWidget(),
|
||||
toqstr(title),
|
||||
toqstr(formatted(message)));
|
||||
}
|
||||
|
@ -12,7 +12,7 @@
|
||||
#ifndef QLKEY_H
|
||||
#define QLKEY_H
|
||||
|
||||
#include <qnamespace.h>
|
||||
#include <Qt>
|
||||
#include <string>
|
||||
|
||||
|
||||
|
@ -26,8 +26,7 @@
|
||||
#include <QComboBox>
|
||||
#include <QCheckBox>
|
||||
#include <QPalette>
|
||||
#include <qlineedit.h>
|
||||
#include <qtextcodec.h>
|
||||
#include <QLineEdit>
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
@ -37,28 +36,7 @@ namespace lyx {
|
||||
using support::isStrDbl;
|
||||
|
||||
using std::vector;
|
||||
using std::make_pair;
|
||||
using std::string;
|
||||
using std::pair;
|
||||
using std::endl;
|
||||
|
||||
|
||||
string makeFontName(string const & family, string const & foundry)
|
||||
{
|
||||
if (foundry.empty())
|
||||
return family;
|
||||
return family + " [" + foundry + ']';
|
||||
}
|
||||
|
||||
|
||||
pair<string, string> parseFontName(string const & name)
|
||||
{
|
||||
string::size_type const idx = name.find('[');
|
||||
if (idx == string::npos || idx == 0)
|
||||
return make_pair(name, string());
|
||||
return make_pair(name.substr(0, idx - 1),
|
||||
name.substr(idx + 1, name.size() - idx - 2));
|
||||
}
|
||||
|
||||
|
||||
string widgetsToLength(QLineEdit const * input, LengthCombo const * combo)
|
||||
@ -96,7 +74,7 @@ Length widgetsToLength(QLineEdit const * input, QComboBox const * combo)
|
||||
void lengthToWidgets(QLineEdit * input, LengthCombo * combo,
|
||||
Length const & len, Length::UNIT /*defaultUnit*/)
|
||||
{
|
||||
combo->setCurrentItem(Length(len).unit());
|
||||
combo->setCurrentItem(len.unit());
|
||||
input->setText(QString::number(Length(len).value()));
|
||||
}
|
||||
|
||||
@ -165,63 +143,4 @@ QString const qt_(string const & str)
|
||||
return toqstr(_(str));
|
||||
}
|
||||
|
||||
|
||||
docstring const formatted(docstring const & text, int w)
|
||||
{
|
||||
docstring sout;
|
||||
|
||||
if (text.empty())
|
||||
return sout;
|
||||
|
||||
docstring::size_type curpos = 0;
|
||||
docstring line;
|
||||
|
||||
for (;;) {
|
||||
docstring::size_type const nxtpos1 = text.find(' ', curpos);
|
||||
docstring::size_type const nxtpos2 = text.find('\n', curpos);
|
||||
docstring::size_type const nxtpos = std::min(nxtpos1, nxtpos2);
|
||||
|
||||
docstring const word =
|
||||
nxtpos == docstring::npos ?
|
||||
text.substr(curpos) :
|
||||
text.substr(curpos, nxtpos - curpos);
|
||||
|
||||
bool const newline = (nxtpos2 != docstring::npos &&
|
||||
nxtpos2 < nxtpos1);
|
||||
|
||||
docstring const line_plus_word =
|
||||
line.empty() ? word : line + char_type(' ') + word;
|
||||
|
||||
// FIXME: make w be size_t
|
||||
if (int(line_plus_word.length()) >= w) {
|
||||
sout += line + char_type('\n');
|
||||
if (newline) {
|
||||
sout += word + char_type('\n');
|
||||
line.erase();
|
||||
} else {
|
||||
line = word;
|
||||
}
|
||||
|
||||
} else if (newline) {
|
||||
sout += line_plus_word + char_type('\n');
|
||||
line.erase();
|
||||
|
||||
} else {
|
||||
if (!line.empty())
|
||||
line += char_type(' ');
|
||||
line += word;
|
||||
}
|
||||
|
||||
if (nxtpos == docstring::npos) {
|
||||
if (!line.empty())
|
||||
sout += line;
|
||||
break;
|
||||
}
|
||||
|
||||
curpos = nxtpos + 1;
|
||||
}
|
||||
|
||||
return sout;
|
||||
}
|
||||
|
||||
} // namespace lyx
|
||||
|
@ -14,25 +14,20 @@
|
||||
#define QTHELPERS_H
|
||||
|
||||
#include "Length.h"
|
||||
#include "support/docstring.h"
|
||||
#include "support/qstring_helpers.h"
|
||||
|
||||
#include <QString>
|
||||
#include <utility>
|
||||
#include <string>
|
||||
|
||||
class QComboBox;
|
||||
class QLineEdit;
|
||||
class QCheckBox;
|
||||
class QString;
|
||||
class QWidget;
|
||||
|
||||
class LengthCombo;
|
||||
|
||||
namespace lyx {
|
||||
|
||||
std::string makeFontName(std::string const & family, std::string const & foundry);
|
||||
|
||||
std::pair<std::string,std::string> parseFontName(std::string const & name);
|
||||
|
||||
/// method to get a Length from widgets (LengthCombo)
|
||||
std::string widgetsToLength(QLineEdit const * input, LengthCombo const * combo);
|
||||
/// method to get a Length from widgets (QComboBox)
|
||||
@ -49,30 +44,9 @@ void lengthToWidgets(QLineEdit * input, LengthCombo * combo,
|
||||
void lengthAutoToWidgets(QLineEdit * input, LengthCombo * combo,
|
||||
Length const & len, Length::UNIT defaultUnit);
|
||||
|
||||
//FIXME setAutoTextCB should really take an argument, as indicated, that
|
||||
//determines what text is to be written for "auto". But making
|
||||
//that work involves more extensive revisions than we now want
|
||||
//to make, since "auto" also appears in updateContents() (see
|
||||
//GuiGraphics.cpp).
|
||||
//The right way to do this, I think, would be to define a class
|
||||
//checkedLengthSet (and a partnering labeledLengthSete) that encapsulated
|
||||
//the checkbox, line edit, and length combo together, and then made e.g.
|
||||
//lengthToWidgets, widgetsToLength, etc, all public methods of that class.
|
||||
//Perhaps even the validator could be exposed through it.
|
||||
/**
|
||||
* sets a checkbox-line edit-length combo group, using "text" if the
|
||||
* checkbox is unchecked and clearing the line edit if it previously
|
||||
* said "text".
|
||||
*/
|
||||
void setAutoTextCB(QCheckBox * checkBox, QLineEdit * lineEdit,
|
||||
LengthCombo * lengthCombo/*, string text = "auto"*/);
|
||||
|
||||
/// colors a widget red if invalid
|
||||
void setValid(QWidget * widget, bool valid);
|
||||
|
||||
/// format a string to the given width
|
||||
docstring const formatted(docstring const & text, int w = 80);
|
||||
|
||||
|
||||
/**
|
||||
* qt_ - i18nize string and convert to QString
|
||||
|
@ -15,8 +15,9 @@
|
||||
#define SOCKET_CALLBACK_H
|
||||
|
||||
|
||||
#include <qobject.h>
|
||||
#include <qsocketnotifier.h>
|
||||
#include <QObject>
|
||||
#include <QSocketNotifier>
|
||||
|
||||
#include <boost/scoped_ptr.hpp>
|
||||
#include <boost/function.hpp>
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user