#include <iomanip>
#include <sstream>
#include <algorithm>
+#include <utility>
using namespace Ui;
}
+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;
}
// 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);
#else
pathCB->setVisible(false);
#endif
-
}
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));
}
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]));
- }
- }
}
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();
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;
if (!current.isEmpty()) {
QList<QListWidgetItem *> const item =
convertersLW->findItems(current, Qt::MatchExactly);
- if (item.size()>0)
+ if (!item.isEmpty())
convertersLW->setCurrentItem(item.at(0));
}
// 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();
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();
}
// 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());
-
- 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);
+ 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();
+
+ 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);
}
-
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));
}
{
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));
}
PrefIdentity::PrefIdentity(QWidget * parent)
-: PrefModule(_("Identity"), 0, parent)
+ : PrefModule(_("Identity"), 0, parent)
{
setupUi(this);
return controller().converters();
}
+
Formats & GuiPrefsDialog::formats()
{
return controller().formats();
}
+
Movers & GuiPrefsDialog::movers()
{
return controller().movers();
}
+
void GuiPrefsDialog::applyView()
{
apply(controller().rc());
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;
+
+ 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;
}
-};
-} // anonymous namespace
+ return sout;
+}
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.
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),
toqstr(formatted(message)));
return;
}
- MessageBox mb;
- mb.warning(qApp->focusWidget(),
+ QMessageBox::warning(qApp->focusWidget(),
toqstr(title),
toqstr(formatted(message)));
}
toqstr(formatted(message)));
return;
}
- MessageBox mb;
- mb.critical(qApp->focusWidget(),
+ QMessageBox::critical(qApp->focusWidget(),
toqstr(title),
toqstr(formatted(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)));
}
#include <QComboBox>
#include <QCheckBox>
#include <QPalette>
-#include <qlineedit.h>
-#include <qtextcodec.h>
+#include <QLineEdit>
#include <algorithm>
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)
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()));
}
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
#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)
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