1 /*===========================================================================
2 *
3 * PUBLIC DOMAIN NOTICE
4 * National Center for Biotechnology Information
5 *
6 * This software/database is a "United States Government Work" under the
7 * terms of the United States Copyright Act. It was written as part of
8 * the author's official duties as a United States Government employee and
9 * thus cannot be copyrighted. This software/database is freely available
10 * to the public for use. The National Library of Medicine and the U.S.
11 * Government have not placed any restriction on its use or reproduction.
12 *
13 * Although all reasonable efforts have been taken to ensure the accuracy
14 * and reliability of the software and data, the NLM and the U.S.
15 * Government do not and cannot warrant the performance or results that
16 * may be obtained by using this software or data. The NLM and the U.S.
17 * Government disclaim all warranties, express or implied, including
18 * warranties of performance, merchantability or fitness for any particular
19 * purpose.
20 *
21 * Please cite the author in any work or product based on this material.
22 *
23 * ===========================================================================
24 *
25 */
26
27 #include "sratoolbar.h"
28 #include "sratoolkitglobals.h"
29
30 #include <QtWidgets>
31
32 #define TOOLBAR_BUTTON_WIDTH_SHORT 96
33 #define TOOLBAR_BUTTON_WIDTH_LONG 192
34 #define TOOLBAR_BUTTON_HEIGHT 64
35
SRAToolBar(QWidget * parent)36 SRAToolBar::SRAToolBar ( QWidget *parent )
37 : QWidget ( parent )
38 , isExpanded ( false )
39 {
40 setObjectName ( "tool_bar_view" );
41 setFixedWidth ( TOOLBAR_WIDTH_FACTOR );
42
43 init ();
44 }
45
init()46 void SRAToolBar::init ()
47 {
48 QButtonGroup *toolBar = new QButtonGroup ( this );
49 toolBar -> setExclusive ( true );
50 connect ( toolBar, SIGNAL ( buttonClicked ( int ) ), this , SLOT ( switchTool ( int ) ) );
51
52 home_button = new QPushButton ();
53 home_button -> setObjectName ( "tool_bar_button" );
54 home_button -> setProperty ( "type", "home" );
55 home_button -> setFixedHeight ( 72 );
56 home_button -> setCheckable ( true );
57 home_button -> setChecked ( true );
58
59 config_button = new QPushButton ();
60 config_button -> setObjectName ( "tool_bar_button" );
61 config_button -> setIcon ( QIcon ( img_path + "ncbi_config_button.svg" ) );
62 config_button -> setFixedHeight ( TOOLBAR_BUTTON_HEIGHT );
63 config_button -> setCheckable ( true );
64
65 diagnostics_button = new QPushButton ();
66 diagnostics_button -> setObjectName ( "tool_bar_button" );
67 diagnostics_button -> setIcon ( QIcon ( img_path + "ncbi_diagnostics_button.svg" ) );
68 diagnostics_button -> setFixedHeight ( TOOLBAR_BUTTON_HEIGHT );
69 diagnostics_button -> setCheckable ( true );
70
71 expand_button = new QPushButton ();
72 connect ( expand_button, SIGNAL ( clicked () ), this, SLOT ( expand () ) );
73 expand_button -> setObjectName ( "tool_bar_button" );
74 expand_button -> setProperty ( "type", "expand" );
75 expand_button -> setFixedHeight ( 48 );
76
77 updateButtonIcons ();
78
79 QFrame *line = new QFrame ();
80 line -> setObjectName ( "spacer_line" );
81 line -> setFrameShape ( QFrame::HLine );
82 line -> setFixedHeight ( 2 );
83 line -> setMinimumWidth ( width () * .8 );
84
85 QFrame *line2= new QFrame ();
86 line2 -> setObjectName ( "spacer_line" );
87 line2 -> setFrameShape ( QFrame::HLine );
88 line2 -> setFixedHeight ( 2 );
89 line2 -> setMinimumWidth ( width () * .8 );
90
91 toolBar -> addButton ( home_button );
92 toolBar -> setId ( home_button, 0 );
93
94 toolBar -> addButton ( config_button );
95 toolBar -> setId ( config_button, 1 );
96
97 toolBar -> addButton ( diagnostics_button );
98 toolBar -> setId ( diagnostics_button, 2 );
99
100 QVBoxLayout *layout = new QVBoxLayout ( );
101 layout -> setMargin ( 0 );
102 layout -> setSpacing ( 0 );
103
104 layout -> addWidget ( home_button );
105 layout -> addSpacing ( 20 );
106 layout -> addWidget ( line );
107 layout -> addSpacing ( 12 );
108 layout -> addWidget ( config_button );
109 layout -> addSpacing ( 8 );
110 layout -> addWidget ( diagnostics_button );
111 layout -> addSpacing ( 20 );
112 layout -> addWidget ( line2 );
113
114 layout -> addWidget ( expand_button, 0, Qt::AlignBottom );
115
116 setLayout ( layout );
117 }
118
updateButtonIcons()119 void SRAToolBar :: updateButtonIcons ()
120 {
121 if ( isExpanded )
122 {
123 home_button -> setIcon ( QIcon ( img_path + "ncbi_logo_long.svg") . pixmap ( QSize ( 176, 48 ) ) );
124 home_button -> setIconSize ( QSize ( TOOLBAR_BUTTON_WIDTH_LONG, 70 ) );
125
126 config_button -> setText ( "Configuration" );
127 diagnostics_button -> setText ("Diagnostics ");
128
129 expand_button -> setIcon ( QIcon ( img_path + "ncbi_expand_button_close.svg" ) );
130 expand_button -> setIconSize ( QSize ( TOOLBAR_BUTTON_WIDTH_LONG, 48 ) );
131 }
132 else
133 {
134 home_button -> setIcon ( QIcon ( img_path + "ncbi_helix_vertical.svg") );
135 home_button -> setIconSize ( QSize ( TOOLBAR_BUTTON_WIDTH_SHORT, TOOLBAR_BUTTON_HEIGHT ) );
136
137 config_button -> setText ( "" );
138 config_button -> setIconSize ( QSize ( TOOLBAR_BUTTON_WIDTH_SHORT, TOOLBAR_BUTTON_HEIGHT ) );
139
140 diagnostics_button -> setText ( "" );
141 diagnostics_button -> setIconSize ( QSize ( TOOLBAR_BUTTON_WIDTH_SHORT, TOOLBAR_BUTTON_HEIGHT ) );
142
143 expand_button -> setIcon ( QIcon ( img_path + "ncbi_expand_button_open.svg" ) );
144 expand_button -> setIconSize ( QSize ( TOOLBAR_BUTTON_WIDTH_SHORT, 48 ) );
145 }
146 }
147
switchTool(int tool)148 void SRAToolBar :: switchTool ( int tool )
149 {
150 emit toolSwitched ( tool );
151 }
152
expand()153 void SRAToolBar :: expand ()
154 {
155 int s = size () . width ();
156 if ( isExpanded )
157 s = s - TOOLBAR_WIDTH_FACTOR;
158 else
159 s = s + TOOLBAR_WIDTH_FACTOR;;
160
161 isExpanded = !isExpanded;
162 resize ( QSize ( s, size () . height () ) );
163 setFixedWidth ( s );
164
165 updateButtonIcons ();
166
167 emit expanded ( isExpanded );
168 }
169
paintEvent(QPaintEvent * e)170 void SRAToolBar :: paintEvent ( QPaintEvent *e )
171 {
172 QPainter painter ( this );
173
174 QLinearGradient gradient = sraTemplate -> getBaseGradient();
175 gradient . setStart ( size () . width () / 2, 0 );
176 gradient . setFinalStop ( size () . width () / 2, size () . height () );
177
178 painter.setBrush ( gradient );
179
180 painter.drawRect ( 0, 0, size () . width (), size () . height () );
181
182 show ();
183
184 QWidget::paintEvent(e);
185 }
186
187
188