aboutsummaryrefslogtreecommitdiff
path: root/lumina-desktop/desktop-plugins/notepad/NotepadPlugin.cpp
blob: d3e1e10d7b78008d66db946ec3f2939d8c4842ac (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#include "NotepadPlugin.h"

#include <LuminaXDG.h>
#include "LSession.h"


NotePadPlugin::NotePadPlugin(QWidget* parent, QString ID) : LDPlugin(parent, ID){
  QVBoxLayout *vlay = new QVBoxLayout();
  this->setLayout( new QVBoxLayout() );
    this->layout()->setContentsMargins(0,0,0,0);
    vlay->setContentsMargins(3,3,3,3);
    frame = new QFrame(this);
      frame->setObjectName("notepadbase");
      frame->setStyleSheet("QFrame#notepadbase{border-width: 1px; background: rgba(255,255,255,50); color: black;} QFrame{ border: none; border-radius: 3px; background: rgba(255,255,255,100); color: black;}");
    this->layout()->addWidget(frame);
    frame->setLayout(vlay);
   
  //Setup the title bar header buttons
  QHBoxLayout *hlay = new QHBoxLayout();
  next = new QToolButton(this);
    next->setAutoRaise(true);
  prev = new QToolButton(this);
    prev->setAutoRaise(true);
  add = new QToolButton(this);
    add->setAutoRaise(true);
  rem = new QToolButton(this);
    rem->setAutoRaise(true);
  label = new QLabel(this);
    label->setAlignment(Qt::AlignCenter);
    hlay->addWidget(prev);
    hlay->addWidget(next);
    hlay->addWidget(label);
    hlay->addWidget(add);
    hlay->addWidget(rem);
    vlay->addLayout(hlay);
	
  //Setup the main text widget
  edit = new QPlainTextEdit(this);
    edit->setReadOnly(false);
    vlay->addWidget(edit);
	
  //Now setup the initial values
  cnote = this->settings->value("currentNote", 1).toInt();
  maxnote = this->settings->value("availableNotes",1).toInt();
  this->setInitialSize(200,300);
  //Setup the button connections
  connect(next, SIGNAL(clicked()), this, SLOT(nextNote()) );
  connect(prev, SIGNAL(clicked()), this, SLOT(prevNote()) );
  connect(add, SIGNAL(clicked()), this, SLOT(newNote()) );
  connect(rem, SIGNAL(clicked()), this, SLOT(remNote()) );
  connect(edit, SIGNAL(textChanged()), this, SLOT(noteChanged()) );
  QTimer::singleShot(0,this, SLOT(loadIcons()) );
  QTimer::singleShot(0,this, SLOT(updateContents()) );
  
}

NotePadPlugin::~NotePadPlugin(){

}

void NotePadPlugin::nextNote(){
  cnote++;
  if(cnote>maxnote){ cnote = 1; } //go to the first
  updateContents();  
}

void NotePadPlugin::prevNote(){
  cnote--;
  if(cnote<1){ cnote = maxnote; } //go to the last
  updateContents();  	
}

void NotePadPlugin::newNote(){
  maxnote++;
  cnote = maxnote;
  updateContents();
}

void NotePadPlugin::remNote(){
  //Clear the current note
  settings->remove("Note-"+QString::number(cnote));
  //If the last note, also decrease the max number
  if(cnote==maxnote && maxnote>1){ maxnote--; }
  //Now go to the previous note
  cnote--;
  if(cnote<1){ cnote = maxnote; }
  updateContents();
}

void NotePadPlugin::updateContents(){
  next->setEnabled(cnote<maxnote);
  prev->setEnabled(cnote>1);
  label->setText( QString(tr("Note #%1")).arg(QString::number(cnote)) );
  settings->setValue("currentNote", cnote);
  settings->setValue("availableNotes", maxnote);
  edit->setPlainText( settings->value("Note-"+QString::number(cnote), "").toString() );
}


void NotePadPlugin::noteChanged(){
  //Save the current text
  settings->setValue("Note-"+QString::number(cnote), edit->toPlainText());
}


void NotePadPlugin::loadIcons(){
  next->setIcon( LXDG::findIcon("go-next-view","") );
  prev->setIcon( LXDG::findIcon("go-previous-view","") );
  add->setIcon( LXDG::findIcon("document-new","") );
  rem->setIcon( LXDG::findIcon("document-close","") );
}
bgstack15