* show symbol panels in proper size when detached from math panel (always layed out in 5 cols)

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@15988 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Edwin Leuven 2006-11-19 17:12:33 +00:00
parent 815da6867e
commit 17bf0023c7
4 changed files with 29 additions and 142 deletions

View File

@ -14,7 +14,6 @@
#include "QMath.h"
#include <QPixmap>
#include <QResizeEvent>
#include <QScrollArea>
#include <QMenu>
#include <QPushButton>
@ -98,11 +97,8 @@ QMathDialog::QMathDialog(QMath * form)
}
//functionsLW->setFixedWidth(functionsLW->sizeHint().width());
// add first symbol panel
addPanel(0);
// show first symbol panel
showingPanel(0);
// 5 buttons + 2 margins + 1 scrollbar
symbolWS->setFixedWidth(5*40 + 2*10 + 15 );
// add menu's to the buttons
QMenu * m = new QMenu(spacePB);
@ -180,10 +176,7 @@ void QMathDialog::showingPanel(int num)
IconPalette * QMathDialog::makePanel(QWidget * parent, char const ** entries)
{
IconPalette * p = new IconPalette(parent);
for (int i = 0; *entries[i]; ++i) {
p->add(QPixmap(toqstr(find_xpm(entries[i]))), entries[i], string("\\") + entries[i]);
}
IconPalette * p = new IconPalette(parent, entries);
// Leave these std:: qualifications alone !
connect(p, SIGNAL(button_clicked(const std::string &)),
this, SLOT(symbol_clicked(const std::string &)));
@ -196,7 +189,6 @@ void QMathDialog::addPanel(int num)
{
QScrollArea * sc = new QScrollArea(symbolWS);
IconPalette * p = makePanel(this, panels[num]);
p->resize(40 * 5, p->height());
sc->setWidget(p);
panel_index[num] = symbolWS->addWidget(sc);
}
@ -223,16 +215,12 @@ void QMathDialog::delimiterClicked()
void QMathDialog::expandClicked()
{
int const id = symbolsCO->currentIndex();
IconPalette * p = makePanel(0, panels[id]);
p->setFixedWidth(40 * 15 + 20);
IconPalette * p = makePanel(this, panels[id]);
string s = "LyX: ";
s += fromqstr(symbolsCO->currentText());
p->setWindowTitle(toqstr(s));
p->resize(40 * 5, p->height());
p->setWindowFlags(Qt::Dialog);
p->show();
p->resize(40 * 5 + 20, 40 * p->numRows() + 20);
p->setMinimumSize(40 * 5 + 20, 40 * 1 + 20);
p->setMaximumWidth (40 * p->numButtons() + 20);
}

View File

@ -20,11 +20,10 @@
class QListWidgetItem;
namespace lyx {
namespace frontend {
class IconPalette;
namespace frontend {
class QMAction : public QAction {
Q_OBJECT
public:

View File

@ -11,53 +11,41 @@
#include <config.h>
#include "iconpalette.h"
#include "debug.h"
#include "qt_helpers.h"
#include "controllers/ControlMath.h" // for find_xpm
#include <QVBoxLayout>
#include <QPixmap>
#include <QHBoxLayout>
#include <QGridLayout>
#include <QResizeEvent>
#include <QLayout>
#include <QPushButton>
#include <QToolTip>
using std::endl;
using std::make_pair;
using std::max;
using std::string;
using std::vector;
namespace lyx {
namespace frontend {
int const button_size = 32;
IconPalette::IconPalette(QWidget * parent)
: QWidget(parent), maxcol_(-1)
IconPalette::IconPalette(QWidget * parent, char const ** entries)
: QWidget(parent)
{
QVBoxLayout * top = new QVBoxLayout(this);
QHBoxLayout * row = new QHBoxLayout(this);
layout_ = new QGridLayout(this);
top->insertLayout(-1, row);
row->insertLayout(-1, layout_);
row->addStretch(0);
top->addStretch(0);
}
QGridLayout * layout_ = new QGridLayout(this);
layout_->setSpacing(0);
int const button_size = 40;
for (int i = 0; *entries[i]; ++i) {
QPushButton * p = new QPushButton;
p->setFixedSize(button_size, button_size);
p->setIcon(QPixmap(toqstr(lyx::frontend::find_xpm(entries[i]))));
p->setToolTip(toqstr(string("\\") + entries[i]));
connect(p, SIGNAL(clicked()), this, SLOT(clicked()));
buttons_.push_back(make_pair(p, entries[i]));
// put in a grid layout with 5 cols
int const row = i/5;
layout_->addWidget(p, row, i - 5*row);
}
void IconPalette::add(QPixmap const & pixmap, string name, string tooltip)
{
QPushButton * p = new QPushButton(this);
p->setFixedSize(button_size, button_size);
p->setIcon(QIcon(pixmap));
p->setToolTip(toqstr(tooltip));
connect(p, SIGNAL(clicked()), this, SLOT(clicked()));
buttons_.push_back(make_pair(p, name));
}
@ -75,79 +63,7 @@ void IconPalette::clicked()
}
void IconPalette::resizeEvent(QResizeEvent * e)
{
QWidget::resizeEvent(e);
lyxerr[Debug::GUI] << "resize panel to "
<< e->size().width() << ',' << e->size().height() << endl;
int maxcol = e->size().width() / button_size;
if (!layout_->isEmpty() && maxcol == maxcol_)
return;
int cols = max(width() / button_size, 1);
int rows = max(int(buttons_.size() / cols), 1);
if (buttons_.size() % cols )
++rows;
lyxerr[Debug::GUI] << "Laying out " << buttons_.size() << " widgets in a "
<< cols << 'x' << rows << " grid." << endl;
setUpdatesEnabled(false);
// clear layout
int i = 0;
QLayoutItem *child;
while ((child = layout_->itemAt(i)) != 0) {
layout_->takeAt(i);
++i;
}
layout_->invalidate();
vector<Button>::const_iterator it(buttons_.begin());
vector<Button>::const_iterator const end(buttons_.end());
for (int i = 0; i < rows; ++i) {
for (int j = 0; j < cols; ++j) {
layout_->addWidget(it->first, i, j);
++it;
if (it == end)
goto out;
}
}
out:
int maxrow_ = int(buttons_.size() / cols);
if (!maxrow_ || buttons_.size() % cols )
++maxrow_;
if(!parent())
setMinimumHeight(button_size * maxrow_ + 20); //prevents the detached panel becomes unreadable
else
resize(cols * button_size, rows * button_size);
maxcol_ = cols;
setUpdatesEnabled(true);
update();
}
int IconPalette::numRows()
{
return maxrow_;
}
int IconPalette::numButtons()
{
return buttons_.size();
}
} // namespace frontend
} // namespace lyx
#include "iconpalette_moc.cpp"

View File

@ -18,13 +18,10 @@
#include <utility>
#include <vector>
class QPixmap;
class QPushButton;
class QGridLayout;
class QResizeEvent;
namespace lyx {
namespace frontend {
/**
* For holding an arbitrary set of icons.
@ -32,34 +29,21 @@ namespace lyx {
class IconPalette : public QWidget {
Q_OBJECT
public:
IconPalette(QWidget * parent);
/// add a button
void add(QPixmap const & pixmap, std::string name, std::string tooltip);
/// get required number of rows.
int numRows();
/// get number of Buttons
int numButtons();
IconPalette(QWidget * parent, char const ** entries);
Q_SIGNALS:
void button_clicked(const std::string &);
protected:
virtual void resizeEvent(QResizeEvent * e);
protected Q_SLOTS:
virtual void clicked();
private:
int maxcol_;
int maxrow_;
QGridLayout * layout_;
typedef std::pair<QPushButton *, std::string> Button;
std::vector<Button> buttons_;
};
} // namespace frontend
} // namespace lyx
#endif // ICONPALETTE_H