summaryrefslogtreecommitdiffstats
path: root/embedded/visualboyadvance/vbaconfigwidget.cpp
blob: e9c00c12d0ad6999de4567720720b3ae9cc19c3c (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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/***************************************************************************
                          vbaconfigwidget.cpp
                             -------------------
    begin                : Thu Nov 29 2001
    copyright            : (C) 2001 by Sandy Meier
    email                : smeier@kdevelop.org
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#include "vbaconfigwidget.h"

#include <qcheckbox.h>
#include <qdir.h>
#include <qlineedit.h>
#include <qradiobutton.h>
#include <qtoolbutton.h>

#include <kfiledialog.h>

#include "domutil.h"


using namespace VisualBoyAdvance;

VBAConfigWidget::VBAConfigWidget(VisualBoyAdvancePart* part,QWidget *parent, const char *name ) : VBAConfigWidgetBase(parent,name) {
  m_part = part;
  QDomDocument &doc = *m_part->projectDom();
  // read 
  QString emulator = DomUtil::readEntry(doc, "/kdevvisualadvance/emulator");
  QString binary = DomUtil::readEntry(doc, "/kdevvisualadvance/binary");
  QString graphicFilter = DomUtil::readEntry(doc, "/kdevvisualadvance/graphicFilter");
  QString scaling = DomUtil::readEntry(doc, "/kdevvisualadvance/scaling");
  QString addOptions = DomUtil::readEntry(doc, "/kdevvisualadvance/addOptions");
  bool terminal = DomUtil::readBoolEntry(doc, "/kdevvisualadvance/terminal");
  bool fullscreen = DomUtil::readBoolEntry(doc, "/kdevvisualadvance/fullscreen");
  // set the widgets

  if(emulator.isNull()){
    emuPathEdit->setText("VisualBoyAdvance"); // default
  }else{
    emuPathEdit->setText(emulator);
  }
  binaryEdit->setText(binary);

  // graphic
  if(graphicFilter.isNull()){
    normalModeButton->setChecked(true);
  }else{
    if(graphicFilter == "-f0"){
      normalModeButton->setChecked(true);
    }
    if(graphicFilter == "-f1"){
      tvModeButton->setChecked(true);
    }
    if(graphicFilter == "-f2"){
      salModeButton->setChecked(true);
    }
    if(graphicFilter == "-f3"){
      superSalModeButton->setChecked(true);
    }
    if(graphicFilter == "-f4"){
      superEagleModeButton->setChecked(true);
    }
  }

  // scaling
  if(scaling.isNull()){
    scaling1Button->setChecked(true);//default
  }else{
    if(scaling == "-1"){
      scaling1Button->setChecked(true);
    }
    if(scaling == "-2"){
      scaling2Button->setChecked(true);
    }
    if(scaling == "-3"){
      scaling3Button->setChecked(true);
    }
    if(scaling == "-4"){
      scaling4Button->setChecked(true);
    }
    
  }
  
  if(fullscreen){
    fullscreenCheckBox->setChecked(true);
  }
  if(terminal){
    terminalCheckBox->setChecked(true);
  }
  
  addOptionsEdit->setText(addOptions);
  connect(emuPathButton,SIGNAL(clicked()),this,SLOT(emuPathButtonClicked()));
}
VBAConfigWidget::~VBAConfigWidget(){
}

void VBAConfigWidget::accept(){
  QDomDocument &doc = *m_part->projectDom();
  
  DomUtil::writeEntry(doc, "/kdevvisualadvance/emulator",emuPathEdit->text());
  DomUtil::writeEntry(doc, "/kdevvisualadvance/binary",binaryEdit->text());
  DomUtil::writeEntry(doc, "/kdevvisualadvance/addOptions",addOptionsEdit->text());
  DomUtil::writeBoolEntry(doc, "/kdevvisualadvance/terminal",terminalCheckBox->isChecked());
  DomUtil::writeBoolEntry(doc, "/kdevvisualadvance/fullscreen",fullscreenCheckBox->isChecked());
  
  if(normalModeButton->isChecked()){
    DomUtil::writeEntry(doc, "/kdevvisualadvance/graphicFilter","-f0");
  }else if (tvModeButton->isChecked()){
    DomUtil::writeEntry(doc, "/kdevvisualadvance/graphicFilter","-f1");
  }else if (salModeButton->isChecked()){
    DomUtil::writeEntry(doc, "/kdevvisualadvance/graphicFilter","-f2");
  }else if (superSalModeButton->isChecked()){
    DomUtil::writeEntry(doc, "/kdevvisualadvance/graphicFilter","-f3");
  }else if (superEagleModeButton->isChecked()){
    DomUtil::writeEntry(doc, "/kdevvisualadvance/graphicFilter","-f4");
  }
  
  if(scaling1Button->isChecked()){
    DomUtil::writeEntry(doc, "/kdevvisualadvance/scaling","-1");
  }else if(scaling2Button->isChecked()){
    DomUtil::writeEntry(doc, "/kdevvisualadvance/scaling","-2");
  }else if(scaling3Button->isChecked()){
    DomUtil::writeEntry(doc, "/kdevvisualadvance/scaling","-3");
  }else if(scaling4Button->isChecked()){
    DomUtil::writeEntry(doc, "/kdevvisualadvance/scaling","-4");
  }
}
void VBAConfigWidget::emuPathButtonClicked(){
  QString emu = KFileDialog::getOpenFileName(QDir::homeDirPath());
  if(!emu.isEmpty()){
    emuPathEdit->setText(emu);
  }
}

#include "vbaconfigwidget.moc"