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 
28 #include "sratoolkit.h"
29 #include "sratoolkitglobals.h"
30 #include "sratoolbar.h"
31 #include "sratoolview.h"
32 #include "config/sraconfigview.h"
33 #include "config/testwidget.h"
34 
35 #include <kapp/main.h>
36 #include <kfg/config.h>
37 #include <kfg/properties.h>
38 #include <kfs/directory.h>
39 #include <klib/rc.h>
40 
41 #include <QtWidgets>
42 
43 
SRAToolkit(QWidget * parent)44 SRAToolkit :: SRAToolkit ( QWidget *parent )
45     : QMainWindow ( parent )
46     , config ( nullptr )
47 {
48     KDirectory *dir = nullptr;
49     rc_t rc = KDirectoryNativeDir ( &dir );
50     if ( rc != 0 )
51         qDebug () << "Failed to get native directory";
52     else
53     {
54         rc = KConfigMake ( &config, dir );
55         if ( rc != 0 )
56             qDebug () << "Failed to make config";
57     }
58 
59     QSize avail_size = QGuiApplication::primaryScreen () -> availableSize ();
60     if ( avail_size . isNull () ||
61          avail_size . width () < 1000 ||
62          avail_size . height () < 600 )
63     {
64         // Minimum size if no size can be determined or screen is too small
65         // 1440 * 900
66         setMinimumSize ( 1440 / 2, 900 / 1.75  );
67     }
68     else
69     {
70         setMinimumSize ( avail_size . width () / 2.5, avail_size . height () / 2 );
71     }
72 
73     init ();
74 }
75 
~SRAToolkit()76 SRAToolkit :: ~SRAToolkit ()
77 {
78 }
79 
init()80 void SRAToolkit :: init ()
81 {
82     mainWidget = new QWidget ();
83     mainWidget -> setObjectName ( "main_widget" );
84     setCentralWidget ( mainWidget );
85 
86     mainLayout = new QHBoxLayout ();
87     mainLayout -> setSpacing ( 0 );
88     mainLayout -> setMargin ( 0 );
89     mainWidget -> setLayout ( mainLayout );
90 
91     toolBar = new SRAToolBar ( this );
92 
93     toolView = new SRAToolView ( config, mainWidget );
94     toolView -> setObjectName ( "sratool_view" );
95 
96     connect ( toolBar, SIGNAL ( toolSwitched ( int ) ), toolView, SLOT ( toolChanged ( int ) ) );
97     connect ( toolBar, SIGNAL ( expanded ( bool ) ), this, SLOT ( expand ( bool ) ) );
98 
99     mainLayout -> addWidget ( toolBar );
100     mainLayout -> addWidget ( toolView );
101 }
102 
103 
expand(bool val)104 void SRAToolkit :: expand ( bool val )
105 {
106     if ( val )
107         resize ( size () . width () + TOOLBAR_WIDTH_FACTOR, size () . height () );
108     else
109         resize ( size () . width () - TOOLBAR_WIDTH_FACTOR, size () . height () );
110 }
111 
paintEvent(QPaintEvent * e)112 void SRAToolkit :: paintEvent ( QPaintEvent *e )
113 {
114     QPainter painter ( this );
115 
116     QLinearGradient gradient = sraTemplate -> getStandardBackground();
117     gradient . setStart ( 0, 0 );
118     gradient . setFinalStop ( size () . width (), size () . height () );
119 
120     painter.setBrush ( gradient );
121 
122     painter.drawRect ( 0, 0, size () . width (), size () . height () );
123     show ();
124 
125     QWidget::paintEvent(e);
126 }
127 
128 
129