summaryrefslogtreecommitdiffstats
path: root/libk3b/tools/k3bmsfedit.cpp
blob: e3d3a7025243c2e6fd938f30fb14e19c756ad379 (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
/* 
 *
 * $Id: k3bmsfedit.cpp 619556 2007-01-03 17:38:12Z trueg $
 * Copyright (C) 2003 Sebastian Trueg <trueg@k3b.org>
 *
 * This file is part of the K3b project.
 * Copyright (C) 1998-2007 Sebastian Trueg <trueg@k3b.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.
 * See the file "COPYING" for the exact licensing terms.
 */



#include "k3bmsfedit.h"
#include "k3bglobals.h"

#include <tqstringlist.h>
#include <tqlineedit.h>
#include <tqstyle.h>
#include <tqfontmetrics.h>
#include <tqapplication.h>



K3bMsfValidator::K3bMsfValidator( TQObject* parent, const char* name )
  : TQRegExpValidator( K3b::Msf::regExp(), parent, name )
{
}



K3bMsfEdit::K3bMsfEdit( TQWidget* parent, const char* name )
  : TQSpinBox( parent, name )
{
  setValidator( new K3bMsfValidator( TQT_TQOBJECT(this) ) );
  setMinValue( 0 );
  // some very high value (10000 minutes)
  setMaxValue( 10000*60*75 );

  connect( this, TQT_SIGNAL(valueChanged(int)),
	   this, TQT_SLOT(slotValueChanged(int)) );
}


K3bMsfEdit::~K3bMsfEdit()
{}


TQSize K3bMsfEdit::sizeHint() const
{
  // more or less copied from TQSpinBox
  constPolish();
  TQSize sz = editor()->sizeHint();
  int h = sz.height();
  TQFontMetrics fm( font() );
  int w = fm.width( "00:00:00" );
  int wx = fm.width( ' ' )*2;
  int frame = tqstyle().pixelMetric( TQStyle::PM_SpinBoxFrameWidth );
  return tqstyle().tqsizeFromContents(TQStyle::CT_SpinBox, this,
				  TQSize( w + wx + downRect().width() + frame*2,
					 h + frame*2).
				  expandedTo( TQApplication::globalStrut() ));
}


TQString K3bMsfEdit::mapValueToText( int value )
{
  return K3b::framesToString( value, true );
}


K3b::Msf K3bMsfEdit::msfValue() const
{
  return K3b::Msf(value());
}


void K3bMsfEdit::setMsfValue( const K3b::Msf& msf )
{
  setValue( msf.totalFrames() );
}


int K3bMsfEdit::mapTextToValue( bool* ok )
{
  return K3b::Msf::fromString( text(), ok ).lba();
}


void K3bMsfEdit::setText( const TQString& str )
{
  bool ok;
  editor()->setText( str );
  setValue( mapTextToValue( &ok) );
}


void K3bMsfEdit::setFrameStyle( int style )
{
  editor()->setFrameStyle( style );
}

void K3bMsfEdit::setLineWidth( int v )
{
  editor()->setLineWidth( v );
}

void K3bMsfEdit::setValue( int v )
{
  int i = editor()->cursorPosition();
  TQSpinBox::setValue( v );
  editor()->setCursorPosition( i );
}

void K3bMsfEdit::stepUp()
{
  setValue( value() + currentStepValue() );
}

void K3bMsfEdit::stepDown()
{
  setValue( value() - currentStepValue() );
}

int K3bMsfEdit::currentStepValue() const
{
  int val = 1;

  // look if we are currently editing minutes or seconds
  TQString text = editor()->text();
  if( text.length() == 8 ) {
    text = text.mid( editor()->cursorPosition() );
    int num = text.contains( ':' );
    if( num == 1 )
      val = 75;
    else if( num == 2 )
      val = 60*75;
  }

  return val;
}


void K3bMsfEdit::slotValueChanged( int v )
{
  emit valueChanged( K3b::Msf(v) );
}

#include "k3bmsfedit.moc"