summaryrefslogtreecommitdiffstats
path: root/src/gui/editors/notation/HeadersGroup.cpp
blob: 38f1a5b417630a87aa24a258761ec544c21eeee7 (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
158
/*
    Rosegarden
    A MIDI and audio sequencer and musical notation editor.
 
    This program is Copyright 2000-2008
        Guillaume Laurent   <[email protected]>,
        Chris Cannam        <[email protected]>,
        Richard Bown        <[email protected]>

    This file is Copyright 2007-2008
        Yves Guillemot      <[email protected]> 
 
    The moral rights of Guillaume Laurent, Chris Cannam, and Richard
    Bown to claim authorship of this work have been asserted.
 
    Other copyrights also apply to some parts of this work.  Please
    see the AUTHORS file and individual file headers for details.
 
    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 included with this distribution for more information.
*/


#include <limits>
#include <tqsize.h>
#include <tqwidget.h>
#include <tqvbox.h>
#include <tqlabel.h>

#include "HeadersGroup.h"
#include "TrackHeader.h"
#include "NotationView.h"
#include "NotePixmapFactory.h"


namespace Rosegarden
{


HeadersGroup::
HeadersGroup(TQWidget *parent, NotationView * nv, Composition * comp) :
        TQVBox(parent),
        m_notationView(nv),
        m_composition(comp),
        m_usedHeight(0),
        m_filler(0),
        m_lastX(INT_MIN),
        m_lastWidth(-1)
{
}

void
HeadersGroup::removeAllHeaders()
{
    TrackHeaderVector::iterator i;
    for (i=m_headers.begin(); i!=m_headers.end(); i++) {
        delete *i;
    }
    m_headers.erase(m_headers.begin(), m_headers.end());

    if (m_filler) {
        delete m_filler;
        m_filler = 0;
    }
    m_usedHeight = 0;
    m_lastWidth = -1;
}

void
HeadersGroup::addHeader(int trackId, int height, int ypos, double xcur)
{
    TrackHeader * sh = new TrackHeader(this, trackId, height, ypos);
    m_headers.push_back(sh);
    m_usedHeight += height;
}

void
HeadersGroup::completeToHeight(int height)
{
    if (height > m_usedHeight) {
        if (!m_filler) m_filler = new TQLabel(this);
        m_filler->setFixedHeight(height - m_usedHeight);
    }
}

void
HeadersGroup::slotUpdateAllHeaders(int x, int y, bool force)
{
    // Minimum header width 
    int headerMinWidth = m_notationView->getHeadersTopFrameMinWidth();

    // Maximum header width (may be overriden by clef and key width)
    int headerMaxWidth = (m_notationView->getCanvasVisibleWidth() * 10) / 100;

    if ((x != m_lastX) || force) {
        m_lastX = x;
        TrackHeaderVector::iterator i;
        int neededWidth = 0;

        // Pass 1 : get the max width needed
        for (i=m_headers.begin(); i!=m_headers.end(); i++) {
            int w = (*i)->lookAtStaff(x, headerMaxWidth);
            if (w > neededWidth) neededWidth = w;
        }

        if (neededWidth < headerMinWidth) neededWidth = headerMinWidth;

        // Only when m_lastWidth is valid (the first time, m_lastWidth = -1)
        if (m_lastWidth > 0) {
            // Don't redraw the headers when change of width is very small
            const int treshold = 10;   // Treshold value should be refined ...
            int deltaWidth = m_lastWidth - neededWidth;
            if ((deltaWidth < treshold) && (deltaWidth > -treshold))
                neededWidth = m_lastWidth;
        }

        // Pass 2 : redraw the headers when necessary
        for (i=m_headers.begin(); i!=m_headers.end(); i++) {
            (*i)->updateHeader(neededWidth);
        }

        if (neededWidth != m_lastWidth) {
            setFixedWidth(neededWidth);
            m_lastWidth = neededWidth;

            // Suppress vertical white stripes on canvas when headers
            // width changes while scrolling
            /// TODO : Limit "setChanged()" to the useful part of canvas
            m_notationView->canvas()->setAllChanged();
            m_notationView->canvas()->update();
        }
    }
}




void
HeadersGroup::setCurrent(TrackId trackId)
{
    TrackHeaderVector::iterator i;
    for (i=m_headers.begin(); i!=m_headers.end(); i++)
                    (*i)->setCurrent((*i)->getId() == trackId);
}

void
HeadersGroup::resizeEvent(TQResizeEvent * ev)
{
    // Needed to avoid gray zone at the right of headers
    // when width is decreasing
    emit headersResized(ev->size().width());
}

}
#include "HeadersGroup.moc"