summaryrefslogtreecommitdiff
path: root/muse2/muse/widgets/pastedialog.cpp
blob: 0f20df22a9aee0ba5f4e1f3db1ee6ade1a961ec3 (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
145
146
147
148
149
150
151
152
153
154
155
156
157
//=========================================================
//  MusE
//  Linux Music Editor
//    $Id: pastedialog.cpp,v 1.1.1.1 2011/05/05 18:51:04 flo93 Exp $
//  (C) Copyright 2011 Florian Jung (flo93@sourceforge.net)
//
//  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; version 2 of
//  the License, or (at your option) any later version.
//
//  This program is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU General Public License for more details.
//
//  You should have received a copy of the GNU General Public License
//  along with this program; if not, write to the Free Software
//  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
//
//=========================================================

#include <QButtonGroup>
#include "pastedialog.h"
#include "xml.h"
#include "gconfig.h"

using MusEGlobal::config;

namespace MusEGui {

int PasteDialog::insert_method = 0;
int PasteDialog::number = 1;
int PasteDialog::raster = 384;
bool PasteDialog::all_in_one_track = 0;
bool PasteDialog::clone = 0;
  
PasteDialog::PasteDialog(QWidget* parent)
	: QDialog(parent)
{
	setupUi(this);
	button_group = new QButtonGroup;
	button_group->addButton(merge_button,0);
	button_group->addButton(move_all_button,1);
	button_group->addButton(move_some_button,2);
	
	raster_spinbox->setSingleStep(config.division);
	
	connect(raster_spinbox, SIGNAL(valueChanged(int)), this, SLOT(raster_changed(int)));
	connect(n_spinbox, SIGNAL(valueChanged(int)), this, SLOT(number_changed(int)));
}

void PasteDialog::pull_values()
{
	insert_method = button_group->checkedId();
	number = n_spinbox->value();
	raster = raster_spinbox->value();
	all_in_one_track = all_in_one_track_checkbox->isChecked();
	clone = clone_checkbox->isChecked();
}

void PasteDialog::accept()
{
	pull_values();
	QDialog::accept();
}

int PasteDialog::exec()
{
	if ((insert_method < 0) || (insert_method > 2)) insert_method=0;
	
	button_group->button(insert_method)->setChecked(true);
	n_spinbox->setValue(number);
	raster_spinbox->setValue(raster);
	all_in_one_track_checkbox->setChecked(all_in_one_track);
	clone_checkbox->setChecked(clone);
	
	return QDialog::exec();
}

QString PasteDialog::ticks_to_quarter_string(int ticks)
{
	if (ticks % config.division == 0)
	{
		return tr("%n quarter(s)", "", ticks/config.division);
	}
	else
	{
		double quarters = (double) ticks/config.division;
		bool one = ( quarters > 0.995 && quarters < 1.005 );
		if (one)
			return tr("%1 quarter", "for floating-point arguments like 1.5").arg(quarters, 0, 'f', 2);
		else
			return tr("%1 quarters", "for floating-point arguments like 1.5").arg(quarters, 0, 'f', 2);
	}
}

void PasteDialog::raster_changed(int r)
{
	raster_quarters->setText(ticks_to_quarter_string(r));
	insert_quarters->setText(ticks_to_quarter_string(r*n_spinbox->value()));
}

void PasteDialog::number_changed(int n)
{
	insert_quarters->setText(ticks_to_quarter_string(n*raster_spinbox->value()));
}


void PasteDialog::read_configuration(MusECore::Xml& xml)
{
	for (;;)
	{
		MusECore::Xml::Token token = xml.parse();
		if (token == MusECore::Xml::Error || token == MusECore::Xml::End)
			break;
			
		const QString& tag = xml.s1();
		switch (token)
		{
			case MusECore::Xml::TagStart:
				if (tag == "insert_method")
					insert_method=xml.parseInt();
				else if (tag == "number")
					number=xml.parseInt();
				else if (tag == "raster")
					raster=xml.parseInt();
				else if (tag == "clone")
					clone=xml.parseInt();
				else if (tag == "all_in_one_track")
					all_in_one_track=xml.parseInt();
				else
					xml.unknown("PasteDialog");
				break;
				
			case MusECore::Xml::TagEnd:
				if (tag == "pastedialog")
					return;
				
			default:
				break;
		}
	}
}

void PasteDialog::write_configuration(int level, MusECore::Xml& xml)
{
	xml.tag(level++, "pastedialog");
	xml.intTag(level, "insert_method", insert_method);
	xml.intTag(level, "number", number);
	xml.intTag(level, "raster", raster);
	xml.intTag(level, "clone", clone);
	xml.intTag(level, "all_in_one_track", all_in_one_track);
	xml.tag(level, "/pastedialog");
}

} // namespace MusEGui