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.
21 package cx.fbn.nevernote.gui;
23 import com.trolltech.qt.core.QSize;
24 import com.trolltech.qt.gui.QTabBar;
25 import com.trolltech.qt.gui.QTabWidget;
26 import com.trolltech.qt.gui.QWidget;
28 import cx.fbn.nevernote.NeverNote;
30 public class TabBrowserWidget extends QTabWidget {
31 private final TabBrowserBar bar;
32 private final NeverNote parent;
33 private QSize closeButtonSize;
35 public TabBrowserWidget(NeverNote parent) {
38 bar = new TabBrowserBar();
40 bar.tabMoved.connect(parent, "tabIndexChanged(int, int)");
43 public int addNewTab(QWidget widget, String title){
44 int index = this.addTab(widget, new String());
45 bar.addNewTab(index, title);
46 this.setTabToolTip(index, title);
48 // タブが1個(多分これが発生するのはアプリ起動時だけ)なら閉じるボタンを隠す
49 // タブが2個以上あったら、一番左のタブの閉じるボタンを復元する
50 int tabCnt = this.count();
52 hideTabCloseButton(0);
53 } else if (tabCnt >= 2) {
54 if (closeButtonSize != null && !bar.tabButton(0, QTabBar.ButtonPosition.RightSide).size().equals(closeButtonSize)) {
55 showTabCloseButton(0);
62 public void setTabTitle(int index, String title) {
63 bar.setTabTitle(index, title);
64 this.setTabToolTip(index, title);
68 public void hideTabCloseButton(int index) {
69 if (closeButtonSize == null) {
70 closeButtonSize = bar.tabButton(index, QTabBar.ButtonPosition.RightSide).size();
72 bar.tabButton(index, QTabBar.ButtonPosition.RightSide).resize(0, 0);
76 public void showTabCloseButton(int index) {
77 if (closeButtonSize != null) {
78 bar.tabButton(index, QTabBar.ButtonPosition.RightSide).resize(closeButtonSize);
80 bar.tabButton(index, QTabBar.ButtonPosition.RightSide).resize(16, 16);