rework mathdelimiter dialog and add size combo...

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@14703 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Edwin Leuven 2006-08-16 14:22:47 +00:00
parent 9690c55e15
commit c98992f774
3 changed files with 156 additions and 298 deletions

View File

@ -11,25 +11,24 @@
#include <config.h>
#include "QDelimiterDialog.h"
#include "iconpalette.h"
#include "QMath.h"
#include "qt_helpers.h"
#include "qt_helpers.h"
#include "controllers/ControlMath.h"
#include <qlabel.h>
#include <qpixmap.h>
#include <qcheckbox.h>
#include "gettext.h"
#include <QPixmap>
#include <QCheckBox>
#include <sstream>
using std::string;
namespace lyx {
namespace frontend {
// FIXME: Implement fixed size delimiters (see qt3 frontend)
namespace {
char const * delim[] = {
@ -40,6 +39,16 @@ char const * delim[] = {
};
char const * const bigleft[] = {"bigl", "Bigl", "biggl", "Biggl", ""};
char const * const bigright[] = {"bigr", "Bigr", "biggr", "Biggr", ""};
char const * const biggui[] = {N_("big size"), N_("Big size"),
N_("bigg size"), N_("Bigg size"), ""};
string do_match(const string & str)
{
if (str == "(") return ")";
@ -61,7 +70,7 @@ string do_match(const string & str)
}
string fix_name(const string & str)
string fix_name(const string & str, bool big)
{
if (str == "slash")
return "/";
@ -69,7 +78,10 @@ string fix_name(const string & str)
return "\\";
if (str == "empty")
return ".";
return str;
if (!big || str == "(" || str == ")" || str == "[" || str == "]")
return str;
return "\\" + str;
}
} // namespace anon
@ -80,69 +92,81 @@ QDelimiterDialog::QDelimiterDialog(QMathDelimiter * form)
{
setupUi(this);
connect( closePB, SIGNAL( clicked() ), this, SLOT( accept() ) );
connect( insertPB, SIGNAL( clicked() ), this, SLOT( insertClicked() ) );
connect(closePB, SIGNAL(clicked()), this, SLOT(accept()));
connect(insertPB, SIGNAL(clicked()), this, SLOT(insertClicked()));
setCaption(qt_("LyX: Delimiters"));
for (int i = 0; *delim[i]; ++i) {
string xpm(find_xpm(delim[i]));
leftIP->add(QPixmap(toqstr(xpm)), delim[i], delim[i]);
rightIP->add(QPixmap(toqstr(xpm)), delim[i], delim[i]);
QPixmap pm = QPixmap(toqstr(find_xpm(delim[i])));
leftCO->addItem(QIcon(pm), "");
rightCO->addItem(QIcon(pm), "");
}
string empty_xpm(find_xpm("empty"));
leftCO->addItem(QIcon(QPixmap(toqstr(empty_xpm))), qt_("(None)"));
rightCO->addItem(QIcon(QPixmap(toqstr(empty_xpm))), qt_("(None)"));
leftIP->add(QPixmap(toqstr(empty_xpm)), "empty", "empty");
rightIP->add(QPixmap(toqstr(empty_xpm)), "empty", "empty");
// Leave these std:: qualifications alone !
connect(leftIP, SIGNAL(button_clicked(const std::string &)),
this, SLOT(ldelim_clicked(const std::string &)));
connect(rightIP, SIGNAL(button_clicked(const std::string &)),
this, SLOT(rdelim_clicked(const std::string &)));
ldelim_clicked("(");
rdelim_clicked(")");
for (int i = 0; *biggui[i]; ++i)
sizeCO->addItem(qt_(biggui[i]));
on_leftCO_activated(0);
}
void QDelimiterDialog::insertClicked()
{
form_->controller().dispatchDelim(fix_name(left_) + ' ' + fix_name(right_));
string const left_ = delim[leftCO->currentIndex()];
string const right_ = delim[rightCO->currentIndex()];
int const size_ = sizeCO->currentIndex();
if (size_ == 0) {
form_->controller().dispatchDelim(
fix_name(left_, false) + ' ' +
fix_name(right_, false));
} else {
std::ostringstream os;
os << '"' << bigleft[size_ - 1] << "\" \""
<< fix_name(left_, true) << "\" \""
<< bigright[size_ - 1] << "\" \""
<< fix_name(right_, true) << '"';
form_->controller().dispatchBigDelim(os.str());
}
}
void QDelimiterDialog::set_label(QLabel * label, const string & str)
void QDelimiterDialog::on_leftCO_activated(int item)
{
label->setUpdatesEnabled(false);
label->setPixmap(QPixmap(toqstr(find_xpm(str))));
label->setUpdatesEnabled(true);
label->update();
}
void QDelimiterDialog::ldelim_clicked(const string & str)
{
left_ = str;
set_label(leftPI, left_);
if (matchCB->isChecked()) {
right_ = do_match(left_);
set_label(rightPI, right_);
string const match = do_match(delim[item]);
int k = 0;
while (delim[k] && delim[k] != match)
++k;
rightCO->setCurrentIndex(k);
}
}
void QDelimiterDialog::rdelim_clicked(const string & str)
void QDelimiterDialog::on_rightCO_activated(int item)
{
right_ = str;
set_label(rightPI, right_);
if (matchCB->isChecked()) {
left_ = do_match(right_);
set_label(leftPI, left_);
string const match = do_match(delim[item]);
int k = 0;
while (delim[k] && delim[k] != match)
++k;
leftCO->setCurrentIndex(k);
}
}
void QDelimiterDialog::on_matchCB_stateChanged(int state)
{
if (state == Qt::Checked)
on_leftCO_activated(leftCO->currentIndex());
}
} // namespace frontend
} // namespace lyx

View File

@ -15,12 +15,6 @@
#include "ui/QDelimiterUi.h"
#include <string>
#include <QLabel>
#include <QDialog>
class IconPalette;
class QLabel;
namespace lyx {
namespace frontend {
@ -31,20 +25,11 @@ class QDelimiterDialog : public QDialog, public Ui::QDelimiterUi {
public:
QDelimiterDialog(QMathDelimiter * form);
public Q_SLOTS:
void ldelim_clicked(const std::string & str);
void rdelim_clicked(const std::string & str);
void on_leftCO_activated(int);
void on_rightCO_activated(int);
void on_matchCB_stateChanged(int);
void insertClicked();
protected:
//needed ? virtual void closeEvent(QCloseEvent * e);
private:
void set_label(QLabel * label, const std::string & str);
/// symbol of left delimiter
std::string left_;
/// symbol of right delimiter
std::string right_;
/// owning form
QMathDelimiter * form_;
};

View File

@ -8,210 +8,55 @@
<rect>
<x>0</x>
<y>0</y>
<width>260</width>
<height>595</height>
<width>206</width>
<height>153</height>
</rect>
</property>
<property name="minimumSize" >
<size>
<width>42</width>
<height>42</height>
</size>
</property>
<property name="windowTitle" >
<string/>
</property>
<property name="sizeGripEnabled" >
<bool>true</bool>
</property>
<layout class="QVBoxLayout" >
<layout class="QGridLayout" >
<property name="margin" >
<number>11</number>
<number>9</number>
</property>
<property name="spacing" >
<number>6</number>
</property>
<item>
<layout class="QHBoxLayout" >
<property name="margin" >
<number>0</number>
<item row="2" column="1" >
<widget class="QComboBox" name="sizeCO" >
<property name="sizePolicy" >
<sizepolicy>
<hsizetype>7</hsizetype>
<vsizetype>0</vsizetype>
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="spacing" >
<number>6</number>
</property>
<item>
<layout class="QVBoxLayout" >
<property name="margin" >
<number>0</number>
</property>
<property name="spacing" >
<number>6</number>
</property>
<item>
<widget class="IconPalette" name="leftIP" >
<property name="sizePolicy" >
<sizepolicy>
<hsizetype>5</hsizetype>
<vsizetype>7</vsizetype>
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" >
<property name="margin" >
<number>0</number>
</property>
<property name="spacing" >
<number>6</number>
</property>
<item>
<spacer>
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType" >
<enum>QSizePolicy::Expanding</enum>
</property>
<property name="sizeHint" >
<size>
<width>20</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<layout class="QVBoxLayout" >
<property name="margin" >
<number>0</number>
</property>
<property name="spacing" >
<number>6</number>
</property>
<item>
<widget class="QLabel" name="leftPI" >
<property name="sizePolicy" >
<sizepolicy>
<hsizetype>1</hsizetype>
<vsizetype>1</vsizetype>
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize" >
<size>
<width>5</width>
<height>5</height>
</size>
</property>
<property name="maximumSize" >
<size>
<width>40</width>
<height>40</height>
</size>
</property>
<property name="toolTip" >
<string>Left delimiter</string>
</property>
<property name="scaledContents" >
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
</layout>
</item>
<item>
<layout class="QVBoxLayout" >
<property name="margin" >
<number>0</number>
</property>
<property name="spacing" >
<number>6</number>
</property>
<item>
<widget class="IconPalette" name="rightIP" >
<property name="sizePolicy" >
<sizepolicy>
<hsizetype>5</hsizetype>
<vsizetype>7</vsizetype>
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" >
<property name="margin" >
<number>0</number>
</property>
<property name="spacing" >
<number>6</number>
</property>
<item>
<layout class="QVBoxLayout" >
<property name="margin" >
<number>0</number>
</property>
<property name="spacing" >
<number>6</number>
</property>
<item>
<widget class="QLabel" name="rightPI" >
<property name="sizePolicy" >
<sizepolicy>
<hsizetype>1</hsizetype>
<vsizetype>1</vsizetype>
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize" >
<size>
<width>5</width>
<height>5</height>
</size>
</property>
<property name="maximumSize" >
<size>
<width>40</width>
<height>40</height>
</size>
</property>
<property name="toolTip" >
<string>Right delimiter</string>
</property>
<property name="scaledContents" >
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
<item>
<spacer>
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType" >
<enum>QSizePolicy::Expanding</enum>
</property>
<property name="sizeHint" >
<size>
<width>20</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item>
<item row="1" column="0" colspan="2" >
<widget class="QCheckBox" name="matchCB" >
<property name="toolTip" >
<string>Match delimiter types</string>
</property>
<property name="text" >
<string>&amp;Keep matched</string>
</property>
<property name="checked" >
<bool>true</bool>
</property>
</widget>
</item>
<item row="0" column="0" colspan="2" >
<layout class="QHBoxLayout" >
<property name="margin" >
<number>0</number>
@ -220,18 +65,57 @@
<number>6</number>
</property>
<item>
<widget class="QCheckBox" name="matchCB" >
<property name="toolTip" >
<string>Match delimiter types</string>
<widget class="QComboBox" name="leftCO" >
<property name="minimumSize" >
<size>
<width>42</width>
<height>42</height>
</size>
</property>
<property name="text" >
<string>&amp;Keep matched</string>
</property>
<property name="checked" >
<bool>true</bool>
<property name="iconSize" >
<size>
<width>32</width>
<height>32</height>
</size>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="rightCO" >
<property name="minimumSize" >
<size>
<width>42</width>
<height>42</height>
</size>
</property>
<property name="iconSize" >
<size>
<width>32</width>
<height>32</height>
</size>
</property>
</widget>
</item>
</layout>
</item>
<item row="2" column="0" >
<widget class="QLabel" name="label" >
<property name="text" >
<string>&amp;Size:</string>
</property>
<property name="buddy" >
<cstring>sizeCO</cstring>
</property>
</widget>
</item>
<item row="3" column="0" colspan="2" >
<layout class="QHBoxLayout" >
<property name="margin" >
<number>0</number>
</property>
<property name="spacing" >
<number>6</number>
</property>
<item>
<spacer>
<property name="orientation" >
@ -242,22 +126,12 @@
</property>
<property name="sizeHint" >
<size>
<width>20</width>
<height>20</height>
<width>50</width>
<height>28</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" >
<property name="margin" >
<number>0</number>
</property>
<property name="spacing" >
<number>6</number>
</property>
<item>
<widget class="QPushButton" name="insertPB" >
<property name="toolTip" >
@ -268,22 +142,6 @@
</property>
</widget>
</item>
<item>
<spacer>
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType" >
<enum>QSizePolicy::Expanding</enum>
</property>
<property name="sizeHint" >
<size>
<width>20</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="closePB" >
<property name="text" >
@ -296,15 +154,6 @@
</layout>
</widget>
<pixmapfunction></pixmapfunction>
<customwidgets>
<customwidget>
<class>IconPalette</class>
<extends></extends>
<header>iconpalette.h</header>
<container>0</container>
<pixmap></pixmap>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>