/guitone-1.0rc5/src/view/widgets/ToolBox.cpp
C++ | 81 lines | 49 code | 13 blank | 19 comment | 8 complexity | 73003c5751d26d308d35d3a3174c7d4a MD5 | raw file
Possible License(s): GPL-3.0
- /***************************************************************************
- * Copyright (C) 2009 by Thomas Keller *
- * me@thomaskeller.biz *
- * *
- * This program is free software; you can redistribute it and/or modify *
- * it under the terms of the GNU General Public License as published by *
- * the Free Software Foundation, either version 3 of the License, or *
- * (at your option) any later version. *
- * *
- * This program is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
- * GNU General Public License for more details. *
- * *
- * You should have received a copy of the GNU General Public License *
- * along with this program. If not, see <http://www.gnu.org/licenses/>. *
- ***************************************************************************/
- #include "ToolBox.h"
- #include "vocab.h"
- ToolBox::ToolBox(QWidget * parent) : QToolBox(parent)
- {
- connect(
- this, SIGNAL(currentChanged(int)),
- this, SLOT(currentIndexChanged(int))
- );
- currentIndexChanged(currentIndex());
- }
- ToolBox::~ToolBox() {}
- void ToolBox::setItemText(int index, const QString & text)
- {
- QString txt(text);
- if (txt.indexOf(QChar(9656)) != 0 &&
- txt.indexOf(QChar(9662)) != 0)
- {
- txt.prepend(" ").prepend(QChar(9656));
- }
- QToolBox::setItemText(index, txt);
- }
- void ToolBox::itemInserted(int index)
- {
- setItemText(index, itemText(index));
- }
- void ToolBox::setCurrentIndex(int index)
- {
- QToolBox::setCurrentIndex(index);
- currentIndexChanged(index);
- }
- void ToolBox::currentIndexChanged(int idx)
- {
- for (int i=0; i<count(); i++)
- {
- QString text = itemText(i);
- // the > arrow is present
- if (text.indexOf(QChar(9656)) == 0)
- continue;
- // the v arrow is present
- if (text.indexOf(QChar(9662)) == 0)
- {
- text = text.mid(1);
- }
- text.prepend(QChar(9656));
- QToolBox::setItemText(i, text);
- }
- QString text = itemText(idx);
- text = text.mid(1);
- text.prepend(QChar(9662));
- QToolBox::setItemText(idx, text);
- }