~d-nelson/research-assistant/nextDNK

« back to all changes in this revision

Viewing changes to RAGUI/NetWidgets.cpp

  • Committer: Viktor Bursian
  • Date: 2013-06-06 13:42:39 UTC
  • Revision ID: vbursian@gmail.com-20130606134239-bx5ks8sg3y9oqckz
Tags: version_0.2.0
first usable version 0.2.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
////////////////////////////////////////////////////////////////////////////////
 
2
/*! @file NetWidgets.cpp   Простенькие виджеты для работы с объектами RANet.
 
3
- Part of RAGUI - Research Assistant Graphical User Interface.
 
4
- Uses  QtGui v.4.6  -  http://qt.nokia.com/
 
5
- Uses  RANet - Research Assistant Net Library (based on ANSI C++).
 
6
- Copyright(C) 2010, Viktor E. Bursian, St.Petersburg, Russia.
 
7
                     Viktor.Bursian@mail.ioffe.ru
 
8
*///////////////////////////////////////////////////////////////////////////////
 
9
#include "NetWidgets.h"
 
10
#include "Nodes.h"
 
11
#include "GeneralGUI.h"
 
12
#include "Net2TreeEvolution.h"
 
13
#include <QMessageBox>
 
14
#include <QMenu>
 
15
namespace RA {
 
16
//------------------------------------------------------------------------------
 
17
//---------------------------------------------------------- sDropNodeWidget ---
 
18
 
 
19
sDropNodeWidget::sDropNodeWidget (QWidget *  parent)
 
20
    :QLabel(parent)
 
21
    ,Prompt(QString2sString(tr("drop datanet node here")))
 
22
{
 
23
  SetValue(sNodePtr(NULL));
 
24
  setStyleSheet("QLabel {background: white; "
 
25
                "border: 1px solid grey; border-radius: 4px; padding: 2px;}");
 
26
  setAcceptDrops(true);
 
27
  setMinimumWidth(height());
 
28
};
 
29
 
 
30
 
 
31
void  sDropNodeWidget::Clear ()
 
32
{
 
33
  SetValue(sNodePtr(NULL));
 
34
};
 
35
 
 
36
 
 
37
void  sDropNodeWidget::SetValue (sNodePtr  V)
 
38
{
 
39
  bool                        ValueChanged = ! (V == Value);
 
40
  Value=V;
 
41
  if( Value.IsNULL() ){
 
42
    setText("");
 
43
    setToolTip(sString2QString(Prompt));
 
44
  }else{
 
45
    sString                     T(Value->Text(HTML));
 
46
    setText(sString2QString(T));
 
47
    /*! @todo{UI trifles} show ToolTip if text goes out of the borders*/
 
48
    if( T.Length() > 20 ){
 
49
      setToolTip(sString2QString(T));
 
50
    }else{
 
51
      setToolTip(QString());
 
52
    };
 
53
  };
 
54
  if( ValueChanged )  emit Changed();
 
55
};
 
56
 
 
57
 
 
58
void sDropNodeWidget::mouseReleaseEvent (QMouseEvent *  event)
 
59
{
 
60
  if( event->button() == Qt::LeftButton )
 
61
    QMessageBox::information(parentWidget()
 
62
        ,tr("Link to a datanet node")
 
63
        ,tr("This field may (or should) contain a link to "
 
64
            "another element of data. \n\n")
 
65
        +sString2QString(Prompt));
 
66
};
 
67
 
 
68
 
 
69
void  sDropNodeWidget::contextMenuEvent (QContextMenuEvent *  event)
 
70
{
 
71
  QMenu                       PopupMenu(parentWidget());
 
72
  PopupMenu.addAction("Clear",this,SLOT(Clear()));
 
73
  PopupMenu.exec(event->globalPos());
 
74
};
 
75
 
 
76
 
 
77
void  sDropNodeWidget::dragEnterEvent (QDragEnterEvent *  event)
 
78
{
 
79
  if( event->mimeData()
 
80
           ->hasFormat(sString2QString(sNet2TreeEvolution::sItem::MimeType)) ){
 
81
    event->setDropAction(Qt::LinkAction);
 
82
    event->accept();
 
83
  };
 
84
};
 
85
 
 
86
 
 
87
void  sDropNodeWidget::dropEvent (QDropEvent *  event)
 
88
{
 
89
  if( event->mimeData()
 
90
           ->hasFormat(sString2QString(sNet2TreeEvolution::sItem::MimeType)) ){
 
91
    event->setDropAction(Qt::LinkAction);
 
92
    event->accept();
 
93
    SetValue(sNet2TreeEvolution::sItem::DraggedItem->AttrValue());
 
94
  };
 
95
};
 
96
 
 
97
//------------------------------------------------------------------------------
 
98
}; //namespace RA
 
99
 
 
100
 
 
101