mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-22 13:18:28 +00:00
* remove old iconpalette (and rename iconpanel to iconpalette)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@17873 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
22fb43fd8f
commit
2632fa5d95
@ -213,7 +213,7 @@ void QLToolbar::add(ToolbarItem const & item)
|
||||
connect(this, SIGNAL(iconSizeChanged(const QSize &)),
|
||||
tb, SLOT(setIconSize(const QSize &)));
|
||||
|
||||
IconPanel * panel = new IconPanel(tb);
|
||||
IconPalette * panel = new IconPalette(tb);
|
||||
connect(this, SIGNAL(updated()), panel, SLOT(updateParent()));
|
||||
ToolbarInfo const & tbb = toolbarbackend.getToolbar(item.name_);
|
||||
ToolbarInfo::item_iterator it = tbb.items.begin();
|
||||
|
@ -3,7 +3,7 @@
|
||||
* This file is part of LyX, the document processor.
|
||||
* Licence details can be found in the file COPYING.
|
||||
*
|
||||
* \author John Levon
|
||||
* \author Edwin Leuven
|
||||
*
|
||||
* Full author contact details are available in file CREDITS.
|
||||
*/
|
||||
@ -16,7 +16,6 @@
|
||||
|
||||
#include <QPixmap>
|
||||
#include <QGridLayout>
|
||||
#include <QPushButton>
|
||||
#include <QToolButton>
|
||||
#include <QToolTip>
|
||||
#include <QToolBar>
|
||||
@ -26,175 +25,10 @@
|
||||
#include <QStyle>
|
||||
#include <QStyleOptionFrame>
|
||||
|
||||
using std::make_pair;
|
||||
using std::string;
|
||||
using std::vector;
|
||||
|
||||
|
||||
namespace lyx {
|
||||
namespace frontend {
|
||||
|
||||
FlowLayout::FlowLayout(QWidget *parent) : QLayout(parent)
|
||||
{
|
||||
setMargin(0);
|
||||
setSpacing(-1);
|
||||
}
|
||||
|
||||
|
||||
FlowLayout::~FlowLayout()
|
||||
{
|
||||
QLayoutItem *item;
|
||||
while ((item = takeAt(0)))
|
||||
delete item;
|
||||
}
|
||||
|
||||
|
||||
void FlowLayout::addItem(QLayoutItem *item)
|
||||
{
|
||||
itemList.append(item);
|
||||
}
|
||||
|
||||
|
||||
int FlowLayout::count() const
|
||||
{
|
||||
return itemList.size();
|
||||
}
|
||||
|
||||
|
||||
QLayoutItem *FlowLayout::itemAt(int index) const
|
||||
{
|
||||
return itemList.value(index);
|
||||
}
|
||||
|
||||
|
||||
QLayoutItem *FlowLayout::takeAt(int index)
|
||||
{
|
||||
if (index >= 0 && index < itemList.size())
|
||||
return itemList.takeAt(index);
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Qt::Orientations FlowLayout::expandingDirections() const
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
bool FlowLayout::hasHeightForWidth() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
int FlowLayout::heightForWidth(int width) const
|
||||
{
|
||||
int height = doLayout(QRect(0, 0, width, 0), true);
|
||||
return height;
|
||||
}
|
||||
|
||||
|
||||
void FlowLayout::setGeometry(const QRect &rect)
|
||||
{
|
||||
QLayout::setGeometry(rect);
|
||||
doLayout(rect, false);
|
||||
}
|
||||
|
||||
|
||||
QSize FlowLayout::sizeHint() const
|
||||
{
|
||||
// default to (max) 6 columns
|
||||
int const cols = qMin(itemList.size(), 6);
|
||||
int const rows = (itemList.size() - 1 )/6 + 1;
|
||||
return QSize(cols * minimumSize().width() + 1,
|
||||
rows * minimumSize().height() + 1);
|
||||
}
|
||||
|
||||
|
||||
QSize FlowLayout::minimumSize() const
|
||||
{
|
||||
QSize size;
|
||||
int const n = itemList.size();
|
||||
for (int i = 0; i < n; ++i) {
|
||||
size = size.expandedTo(itemList.at(i)->minimumSize());
|
||||
}
|
||||
return size;
|
||||
}
|
||||
|
||||
|
||||
int FlowLayout::doLayout(const QRect &rect, bool testOnly) const
|
||||
{
|
||||
int x = rect.x();
|
||||
int y = rect.y();
|
||||
int lineHeight = 0;
|
||||
|
||||
for (int i = 0; i < itemList.size(); ++i) {
|
||||
QLayoutItem * item = itemList.at(i);
|
||||
int nextX = x + item->sizeHint().width() + spacing();
|
||||
if (nextX - spacing() > rect.right() && lineHeight > 0) {
|
||||
x = rect.x();
|
||||
y = y + lineHeight + spacing();
|
||||
nextX = x + item->sizeHint().width() + spacing();
|
||||
lineHeight = 0;
|
||||
}
|
||||
|
||||
if (!testOnly)
|
||||
item->setGeometry(QRect(QPoint(x, y), item->sizeHint()));
|
||||
|
||||
x = nextX;
|
||||
lineHeight = qMax(lineHeight, item->sizeHint().height());
|
||||
}
|
||||
return y + lineHeight - rect.y();
|
||||
}
|
||||
|
||||
|
||||
IconPalette::IconPalette(QWidget * parent, char const ** entries)
|
||||
: QWidget(parent)
|
||||
{
|
||||
FlowLayout * layout_ = new FlowLayout(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]));
|
||||
layout_->addWidget(p);
|
||||
}
|
||||
#ifdef Q_WS_WIN
|
||||
// FIXME: This is a hack to work around bug 2859
|
||||
// http://bugzilla.lyx.org/show_bug.cgi?id=2859
|
||||
// Short description of the bug:
|
||||
/*
|
||||
Open the math panel and detach the operator panel by pressing the
|
||||
"Detach Panel" button. The detached panel is then always set too
|
||||
high in the left upper corner of the screen as in the attached
|
||||
screenshot.
|
||||
*/
|
||||
move(50, 50);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
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) {
|
||||
// emit signal
|
||||
button_clicked(it->second);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
IconPanel::IconPanel(QWidget * parent)
|
||||
IconPalette::IconPalette(QWidget * parent)
|
||||
: QWidget(parent, Qt::Popup)
|
||||
{
|
||||
layout_ = new QGridLayout(this);
|
||||
@ -204,7 +38,7 @@ IconPanel::IconPanel(QWidget * parent)
|
||||
}
|
||||
|
||||
|
||||
void IconPanel::addButton(QAction * action)
|
||||
void IconPalette::addButton(QAction * action)
|
||||
{
|
||||
actions_.push_back(action);
|
||||
QToolButton * tb = new QToolButton;
|
||||
@ -224,14 +58,14 @@ void IconPanel::addButton(QAction * action)
|
||||
}
|
||||
|
||||
|
||||
void IconPanel::clicked(QAction * action)
|
||||
void IconPalette::clicked(QAction * action)
|
||||
{
|
||||
triggered(action);
|
||||
setVisible(false);
|
||||
}
|
||||
|
||||
|
||||
void IconPanel::showEvent(QShowEvent * event)
|
||||
void IconPalette::showEvent(QShowEvent * event)
|
||||
{
|
||||
int hoffset = - parentWidget()->pos().x();
|
||||
int voffset = - parentWidget()->pos().y();
|
||||
@ -271,14 +105,14 @@ void IconPanel::showEvent(QShowEvent * event)
|
||||
}
|
||||
|
||||
|
||||
void IconPanel::hideEvent(QHideEvent * event )
|
||||
void IconPalette::hideEvent(QHideEvent * event )
|
||||
{
|
||||
visible(false);
|
||||
QWidget::hideEvent(event);
|
||||
}
|
||||
|
||||
|
||||
void IconPanel::updateParent()
|
||||
void IconPalette::updateParent()
|
||||
{
|
||||
bool enable = false;
|
||||
for (int i = 0; i < actions_.size(); ++i)
|
||||
@ -291,7 +125,7 @@ void IconPanel::updateParent()
|
||||
}
|
||||
|
||||
|
||||
void IconPanel::paintEvent(QPaintEvent * event)
|
||||
void IconPalette::paintEvent(QPaintEvent * event)
|
||||
{
|
||||
// draw border
|
||||
QPainter p(this);
|
||||
|
@ -4,7 +4,7 @@
|
||||
* This file is part of LyX, the document processor.
|
||||
* Licence details can be found in the file COPYING.
|
||||
*
|
||||
* \author John Levon
|
||||
* \author Edwin Leuven
|
||||
*
|
||||
* Full author contact details are available in file CREDITS.
|
||||
*/
|
||||
@ -13,72 +13,19 @@
|
||||
#define ICONPALETTE_H
|
||||
|
||||
#include <QWidget>
|
||||
#include <QLayout>
|
||||
#include <QRect>
|
||||
#include <QMenu>
|
||||
#include <QWidgetItem>
|
||||
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
#include "Action.h"
|
||||
|
||||
class QPushButton;
|
||||
|
||||
namespace lyx {
|
||||
namespace frontend {
|
||||
|
||||
class FlowLayout : public QLayout
|
||||
{
|
||||
public:
|
||||
FlowLayout(QWidget *parent);
|
||||
~FlowLayout();
|
||||
|
||||
void addItem(QLayoutItem *item);
|
||||
Qt::Orientations expandingDirections() const;
|
||||
bool hasHeightForWidth() const;
|
||||
int heightForWidth(int) const;
|
||||
QSize minimumSize() const;
|
||||
void setGeometry(const QRect &rect);
|
||||
QSize sizeHint() const;
|
||||
QLayoutItem * takeAt(int index);
|
||||
QLayoutItem * itemAt(int index) const;
|
||||
int count() const;
|
||||
|
||||
private:
|
||||
int doLayout(const QRect &rect, bool testOnly) const;
|
||||
QList<QLayoutItem *> itemList;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* For holding an arbitrary set of icons.
|
||||
*/
|
||||
class IconPalette : public QWidget {
|
||||
Q_OBJECT
|
||||
public:
|
||||
IconPalette(QWidget * parent, char const ** entries);
|
||||
|
||||
Q_SIGNALS:
|
||||
void button_clicked(const std::string &);
|
||||
|
||||
protected Q_SLOTS:
|
||||
virtual void clicked();
|
||||
|
||||
private:
|
||||
typedef std::pair<QPushButton *, std::string> Button;
|
||||
std::vector<Button> buttons_;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* For holding an arbitrary set of icons.
|
||||
* is susceptible to replace IconPalette
|
||||
*/
|
||||
class IconPanel : public QWidget {
|
||||
Q_OBJECT
|
||||
public:
|
||||
IconPanel(QWidget * parent);
|
||||
IconPalette(QWidget * parent);
|
||||
void addButton(QAction *);
|
||||
|
||||
public Q_SLOTS:
|
||||
|
Loading…
Reference in New Issue
Block a user