2 * This file is part of NeighborNote
3 * Copyright 2013 Yuki Takahashi
5 * This file may be licensed under the terms of of the
6 * GNU General Public License Version 2 (the ``GPL'').
8 * Software distributed under the License is distributed
9 * on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
10 * express or implied. See the GPL for the specific language
11 * governing rights and limitations.
13 * You should have received a copy of the GPL along with this
14 * program. If not, go to http://www.gnu.org/licenses/gpl.html
15 * or write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 package cx.fbn.nevernote.gui;
22 import com.trolltech.qt.core.QEvent;
23 import com.trolltech.qt.core.QSize;
24 import com.trolltech.qt.core.Qt;
25 import com.trolltech.qt.gui.QCursor;
26 import com.trolltech.qt.gui.QIcon;
27 import com.trolltech.qt.gui.QMouseEvent;
28 import com.trolltech.qt.gui.QPixmap;
29 import com.trolltech.qt.gui.QToolButton;
30 import com.trolltech.qt.gui.QWidget;
32 public class SearchClearButton extends QToolButton {
33 private final QPixmap clearIcon;
34 private final QPixmap clearActiveIcon;
35 private final QPixmap clearPressedIcon;
36 private final String iconPath;
38 public SearchClearButton(QWidget parent, String iconPath) {
40 this.iconPath = iconPath;
42 clearIcon = new QPixmap(this.iconPath + "clear.png");
43 clearActiveIcon = new QPixmap(this.iconPath + "clearActive.png");
44 clearPressedIcon = new QPixmap(this.iconPath + "clearPressed.png");
46 this.setIcon(new QIcon(clearIcon));
47 this.setIconSize(new QSize(16, 16));
48 this.setCursor(new QCursor(Qt.CursorShape.ArrowCursor));
49 this.setStyleSheet("QToolButton { border: none; padding: 0px; }");
54 protected void enterEvent(QEvent e) {
56 this.setIcon(new QIcon(clearActiveIcon));
60 protected void leaveEvent(QEvent e) {
62 this.setIcon(new QIcon(clearIcon));
66 protected void mousePressEvent(QMouseEvent e) {
67 super.mousePressEvent(e);
68 this.setIcon(new QIcon(clearPressedIcon));
72 protected void mouseReleaseEvent(QMouseEvent e) {
73 super.mouseReleaseEvent(e);
74 this.setIcon(new QIcon(clearIcon));