2 * This file is part of NixNote/NeighborNote
\r
3 * Copyright 2009 Randy Baumgarte
\r
5 * This file may be licensed under the terms of of the
\r
6 * GNU General Public License Version 2 (the ``GPL'').
\r
8 * Software distributed under the License is distributed
\r
9 * on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
\r
10 * express or implied. See the GPL for the specific language
\r
11 * governing rights and limitations.
\r
13 * You should have received a copy of the GPL along with this
\r
14 * program. If not, go to http://www.gnu.org/licenses/gpl.html
\r
15 * or write to the Free Software Foundation, Inc.,
\r
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
\r
20 package cx.fbn.nevernote.gui;
\r
22 import java.util.List;
\r
24 import com.trolltech.qt.core.QSize;
\r
25 import com.trolltech.qt.gui.QAction;
\r
26 import com.trolltech.qt.gui.QColor;
\r
27 import com.trolltech.qt.gui.QIcon;
\r
28 import com.trolltech.qt.gui.QMenu;
\r
29 import com.trolltech.qt.gui.QPixmap;
\r
30 import com.trolltech.qt.gui.QWidget;
\r
32 public class ColorMenu extends Object {
\r
34 private final QMenu menu;
\r
36 QColor currentColor;
\r
38 public ColorMenu(QWidget b) {
\r
42 currentColor = new QColor("black");
\r
45 public void setDefault(QColor color) {
\r
46 currentColor = color;
\r
49 private void populateList() {
\r
50 List<String> colorNames = QColor.colorNames();
\r
51 for(int i=0; i<colorNames.size(); i++) {
\r
52 QColor color = new QColor(colorNames.get(i));
\r
53 QPixmap pix = new QPixmap(new QSize(22, 22));
\r
55 QAction newAction = new QAction(new QIcon(pix), "", parent);
\r
56 newAction.setToolTip(colorNames.get(i));
\r
57 newAction.setText(colorNames.get(i));
\r
58 newAction.hovered.connect(this, "itemHovered()");
\r
59 menu.addAction(newAction);
\r
63 @SuppressWarnings("unused")
\r
64 private void itemHovered() {
\r
65 if (menu.activeAction() != null && menu.activeAction().toolTip() != null)
\r
66 currentColor = new QColor(menu.activeAction().toolTip());
\r
69 public QColor getColor() {
\r
70 return currentColor;
\r
73 public QMenu getMenu() {
\r