OSDN Git Service

キーワード検索時に検索範囲を設定できるようにした
[neighbornote/NeighborNote.git] / src / cx / fbn / nevernote / gui / SearchClearButton.java
1 /*
2  * This file is part of NeighborNote
3  * Copyright 2013 Yuki Takahashi
4  * 
5  * This file may be licensed under the terms of of the
6  * GNU General Public License Version 2 (the ``GPL'').
7  *
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.
12  *
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.
17  *
18 */
19
20 package cx.fbn.nevernote.gui;
21
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;
31
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;
37         
38         public SearchClearButton(QWidget parent, String iconPath) {
39                 super(parent);
40                 this.iconPath = iconPath;
41                 
42                 clearIcon = new QPixmap(this.iconPath + "clear.png");
43                 clearActiveIcon = new QPixmap(this.iconPath + "clearActive.png");
44                 clearPressedIcon = new QPixmap(this.iconPath + "clearPressed.png");
45                 
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; }");
50                 this.hide();
51         }
52         
53         @Override
54         protected void enterEvent(QEvent e) {
55                 super.enterEvent(e);
56                 this.setIcon(new QIcon(clearActiveIcon));
57         }
58         
59         @Override
60         protected void leaveEvent(QEvent e) {
61                 super.leaveEvent(e);
62                 this.setIcon(new QIcon(clearIcon));
63         }
64         
65         @Override
66         protected void mousePressEvent(QMouseEvent e) {
67                 super.mousePressEvent(e);
68                 this.setIcon(new QIcon(clearPressedIcon));
69         }
70         
71         @Override
72         protected void mouseReleaseEvent(QMouseEvent e) {
73                 super.mouseReleaseEvent(e);
74                 this.setIcon(new QIcon(clearIcon));
75         }
76 }