2006-03-05 17:24:44 +00:00
|
|
|
/**
|
|
|
|
* \file iconpalette.C
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
*
|
|
|
|
* \author John Levon
|
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include "iconpalette.h"
|
2006-08-17 08:49:05 +00:00
|
|
|
|
|
|
|
#include "debug.h"
|
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
#include "qt_helpers.h"
|
2006-08-17 08:49:05 +00:00
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
#include <QVBoxLayout>
|
|
|
|
#include <QPixmap>
|
|
|
|
#include <QHBoxLayout>
|
2006-05-08 11:44:37 +00:00
|
|
|
#include <QGridLayout>
|
2006-03-05 17:24:44 +00:00
|
|
|
#include <QResizeEvent>
|
2006-08-17 08:49:05 +00:00
|
|
|
#include <QLayout>
|
|
|
|
#include <QPushButton>
|
|
|
|
#include <QToolTip>
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
using std::endl;
|
|
|
|
using std::make_pair;
|
|
|
|
using std::max;
|
|
|
|
using std::string;
|
|
|
|
using std::vector;
|
|
|
|
|
|
|
|
|
|
|
|
int const button_size = 40;
|
|
|
|
|
|
|
|
|
2006-08-17 08:49:05 +00:00
|
|
|
IconPalette::IconPalette(QWidget * parent)
|
|
|
|
: QWidget(parent), maxcol_(-1)
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
|
|
|
QVBoxLayout * top = new QVBoxLayout(this);
|
2006-08-17 08:49:05 +00:00
|
|
|
QHBoxLayout * row = new QHBoxLayout(this);
|
|
|
|
layout_ = new QGridLayout(this);
|
|
|
|
top->insertLayout(-1, row);
|
|
|
|
row->insertLayout(-1, layout_);
|
2006-03-05 17:24:44 +00:00
|
|
|
row->addStretch(0);
|
|
|
|
top->addStretch(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void IconPalette::add(QPixmap const & pixmap, string name, string tooltip)
|
|
|
|
{
|
|
|
|
QPushButton * p = new QPushButton(this);
|
|
|
|
p->setFixedSize(button_size, button_size);
|
2006-08-17 08:49:05 +00:00
|
|
|
p->setIcon(QIcon(pixmap));
|
|
|
|
p->setToolTip(toqstr(tooltip));
|
2006-03-05 17:24:44 +00:00
|
|
|
connect(p, SIGNAL(clicked()), this, SLOT(clicked()));
|
|
|
|
buttons_.push_back(make_pair(p, name));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void IconPalette::clicked()
|
|
|
|
{
|
|
|
|
vector<Button>::const_iterator it(buttons_.begin());
|
|
|
|
vector<Button>::const_iterator const end(buttons_.end());
|
|
|
|
for (; it != end; ++it) {
|
|
|
|
if (sender() == it->first) {
|
2006-06-30 14:11:50 +00:00
|
|
|
// emit signal
|
|
|
|
button_clicked(it->second);
|
2006-03-05 17:24:44 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
2006-04-05 15:10:34 +00:00
|
|
|
int cols = max(width() / button_size, 1);
|
2006-03-05 17:24:44 +00:00
|
|
|
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
|
2006-08-17 08:49:05 +00:00
|
|
|
int i = 0;
|
|
|
|
QLayoutItem *child;
|
|
|
|
while ((child = layout_->itemAt(i)) != 0) {
|
|
|
|
layout_->takeAt(i);
|
|
|
|
++i;
|
|
|
|
}
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
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:
|
|
|
|
|
|
|
|
resize(cols * button_size, rows * button_size);
|
|
|
|
|
|
|
|
maxcol_ = cols;
|
|
|
|
|
|
|
|
setUpdatesEnabled(true);
|
|
|
|
update();
|
|
|
|
}
|
2006-05-18 08:51:12 +00:00
|
|
|
|
|
|
|
#include "iconpalette_moc.cpp"
|