A few more tweaks, fixes and clean-ups

Originally committed to SVN as r108.
This commit is contained in:
Rodrigo Braz Monteiro 2006-02-22 05:30:09 +00:00
parent 25d5516d77
commit 0b862d1727
9 changed files with 92 additions and 101 deletions

View file

@ -96,27 +96,14 @@ BaseGrid::~BaseGrid() {
} }
///////////////
//////////////// // Clears grid
// Select a row void BaseGrid::Clear () {
void BaseGrid::SelectRow(int row, bool addToSelected, bool select) { diagMap.clear();
if (!addToSelected) ClearSelection(); diagPtrMap.clear();
try { selMap.clear();
bool cur = selMap.at(row); yPos = 0;
if (select != cur) { AdjustScrollbar();
selMap.at(row) = select;
if (!addToSelected) Refresh(false);
else {
int w = 0;
int h = 0;
GetClientSize(&w,&h);
RefreshRect(wxRect(0,(row+1-yPos)*lineHeight,w,lineHeight),false);
}
}
}
catch (...) {}
} }
@ -162,6 +149,49 @@ void BaseGrid::MakeCellVisible(int row, int col,bool center) {
} }
////////////////
// Select a row
void BaseGrid::SelectRow(int row, bool addToSelected, bool select) {
if (!addToSelected) ClearSelection();
try {
bool cur = selMap.at(row);
if (select != cur) {
selMap.at(row) = select;
if (!addToSelected) Refresh(false);
else {
int w = 0;
int h = 0;
GetClientSize(&w,&h);
RefreshRect(wxRect(0,(row+1-yPos)*lineHeight,w,lineHeight),false);
}
}
}
catch (...) {}
}
/////////////////////////
// Selects visible lines
void BaseGrid::SelectVisible() {
int rows = GetRows();
bool selectedOne = false;
for (int i=0;i<rows;i++) {
if (IsDisplayed(GetDialogue(i))) {
if (!selectedOne) {
SelectRow(i,false);
MakeCellVisible(i,0);
selectedOne = true;
}
else {
SelectRow(i,true);
}
}
}
}
/////////////////////// ///////////////////////
// Unselects all cells // Unselects all cells
void BaseGrid::ClearSelection() { void BaseGrid::ClearSelection() {
@ -242,15 +272,6 @@ int BaseGrid::GetRows() const {
} }
/////////////////////
// Auto size columns
void BaseGrid::AutoSizeColumn(int col, bool setAsMin) {
(void) col;
(void) setAsMin;
SetColumnWidths();
}
/////////////// ///////////////
// Event table // Event table
BEGIN_EVENT_TABLE(BaseGrid,wxWindow) BEGIN_EVENT_TABLE(BaseGrid,wxWindow)
@ -721,44 +742,60 @@ void BaseGrid::SetColumnWidths() {
if (!byFrame) { if (!byFrame) {
AssTime time; AssTime time;
dc.GetTextExtent(time.GetASSFormated(), &fw, &fh, NULL, NULL, &font); dc.GetTextExtent(time.GetASSFormated(), &fw, &fh, NULL, NULL, &font);
startLen = fw; startLen = fw + 10;
endLen = fw; endLen = fw + 10;
} }
// O(n) widths // O(n) widths
int layerLen = 0;
int actorLen = 0; int actorLen = 0;
int effectLen = 0; int effectLen = 0;
int maxLayer = 0;
int maxStart = 0;
int maxEnd = 0;
AssDialogue *curDiag; AssDialogue *curDiag;
for (int i=0;i<GetRows();i++) { for (int i=0;i<GetRows();i++) {
curDiag = GetDialogue(i); curDiag = GetDialogue(i);
if (curDiag) { if (curDiag) {
// Layer // Layer
dc.GetTextExtent(wxString::Format(_T("%i"),curDiag->Layer), &fw, &fh, NULL, NULL, &font); if (curDiag->Layer > maxLayer) maxLayer = curDiag->Layer;
if (fw > layerLen) layerLen = fw;
// Actor // Actor
dc.GetTextExtent(curDiag->Actor, &fw, &fh, NULL, NULL, &font); if (!curDiag->Actor.IsEmpty()) {
if (fw > actorLen) actorLen = fw; dc.GetTextExtent(curDiag->Actor, &fw, &fh, NULL, NULL, &font);
if (fw > actorLen) actorLen = fw;
}
// Effect // Effect
dc.GetTextExtent(curDiag->Effect, &fw, &fh, NULL, NULL, &font); if (!curDiag->Effect.IsEmpty()) {
if (fw > effectLen) effectLen = fw; dc.GetTextExtent(curDiag->Effect, &fw, &fh, NULL, NULL, &font);
if (fw > effectLen) effectLen = fw;
}
// Times // Times
if (byFrame) { if (byFrame) {
dc.GetTextExtent(wxString::Format(_T("%i"),VFR_Output.CorrectFrameAtTime(curDiag->Start.GetMS(),true)), &fw, &fh, NULL, NULL, &font); int tmp = VFR_Output.CorrectFrameAtTime(curDiag->Start.GetMS(),true);
if (fw > startLen) startLen = fw; if (tmp > maxStart) maxStart = tmp;
dc.GetTextExtent(wxString::Format(_T("%i"),VFR_Output.CorrectFrameAtTime(curDiag->End.GetMS(),true)), &fw, &fh, NULL, NULL, &font); tmp = VFR_Output.CorrectFrameAtTime(curDiag->End.GetMS(),true);
if (fw > endLen) endLen = fw; if (tmp > maxEnd) maxEnd = tmp;
} }
} }
} }
layerLen += 10;
// Finish layer
dc.GetTextExtent(wxString::Format(_T("%i"),maxLayer), &fw, &fh, NULL, NULL, &font);
int layerLen = fw + 10;
// Finish times
if (byFrame) {
dc.GetTextExtent(wxString::Format(_T("%i"),maxStart), &fw, &fh, NULL, NULL, &font);
startLen = fw + 10;
dc.GetTextExtent(wxString::Format(_T("%i"),maxEnd), &fw, &fh, NULL, NULL, &font);
endLen = fw + 10;
}
// Finish actor/effect
if (actorLen) actorLen += 10; if (actorLen) actorLen += 10;
if (effectLen) effectLen += 10; if (effectLen) effectLen += 10;
startLen += 10;
endLen += 10;
// Style length // Style length
int styleLen = 0; int styleLen = 0;

View file

@ -103,14 +103,16 @@ public:
bool IsDisplayed(AssDialogue *line); bool IsDisplayed(AssDialogue *line);
int GetNumberSelection(); int GetNumberSelection();
int GetFirstSelRow(); int GetFirstSelRow();
void SelectVisible();
wxArrayInt GetSelection(bool *continuous=NULL); wxArrayInt GetSelection(bool *continuous=NULL);
void Clear();
void UpdateMaps(); void UpdateMaps();
int GetRows() const; int GetRows() const;
int GetNumberRows() const { return GetRows(); } int GetNumberRows() const { return GetRows(); }
void MakeCellVisible(int row, int col,bool center=true); void MakeCellVisible(int row, int col,bool center=true);
void AutoSizeColumn(int col, bool setAsMin = true);
AssDialogue *GetDialogue(int n); AssDialogue *GetDialogue(int n);
BaseGrid(wxWindow* parent, wxWindowID id, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = wxWANTS_CHARS, const wxString& name = wxPanelNameStr); BaseGrid(wxWindow* parent, wxWindowID id, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = wxWANTS_CHARS, const wxString& name = wxPanelNameStr);

View file

@ -225,7 +225,8 @@ void DialogResample::OnResample (wxCommandEvent &event) {
subs->SetScriptInfo(_T("PlayResY"),wxString::Format(_T("%i"),y2)); subs->SetScriptInfo(_T("PlayResY"),wxString::Format(_T("%i"),y2));
// Flag as modified // Flag as modified
grid->LoadFromAss(); subs->FlagAsModified();
grid->CommitChanges();;
EndModal(0); EndModal(0);
} }

View file

@ -259,7 +259,6 @@ void DialogShiftTimes::OnOK(wxCommandEvent &event) {
Options.Save(); Options.Save();
// End dialog // End dialog
//grid->LoadFromAss(NULL,true);
grid->UpdateMaps(); grid->UpdateMaps();
EndModal(0); EndModal(0);
} }

View file

@ -511,7 +511,6 @@ void DialogTimingProcessor::Process() {
} }
// Update grid // Update grid
//grid->ass->FlagAsModified(); grid->ass->FlagAsModified();
//grid->CommitChanges(); grid->CommitChanges();
grid->LoadFromAss(NULL,true,false);
} }

View file

@ -910,7 +910,7 @@ void FrameMain::LoadVFR(wxString filename) {
if (filename != _T("")) { if (filename != _T("")) {
try { try {
VFR_Output.Load(filename); VFR_Output.Load(filename);
SubsBox->LoadFromAss(NULL,true,true); SubsBox->Refresh(false);
} }
// Fail // Fail
catch (wchar_t *error) { catch (wchar_t *error) {

View file

@ -579,7 +579,6 @@ void SubsEditBox::OnStyleChange(wxCommandEvent &event) {
cur->UpdateData(); cur->UpdateData();
} }
} }
grid->AutoSizeColumn(3);
grid->ass->FlagAsModified(); grid->ass->FlagAsModified();
grid->CommitChanges(); grid->CommitChanges();
grid->EndBatch(); grid->EndBatch();
@ -611,7 +610,6 @@ void SubsEditBox::OnActorChange(wxCommandEvent &event) {
} }
// Update grid // Update grid
grid->AutoSizeColumn(4);
grid->ass->FlagAsModified(); grid->ass->FlagAsModified();
grid->CommitChanges(); grid->CommitChanges();
grid->EndBatch(); grid->EndBatch();
@ -635,7 +633,6 @@ void SubsEditBox::OnLayerChange(wxCommandEvent &event) {
cur->UpdateData(); cur->UpdateData();
} }
} }
grid->AutoSizeColumn(0);
grid->ass->FlagAsModified(); grid->ass->FlagAsModified();
grid->CommitChanges(); grid->CommitChanges();
grid->EndBatch(); grid->EndBatch();

View file

@ -728,18 +728,6 @@ void SubtitlesGrid::LoadDefault (AssFile *_ass) {
} }
///////////////
// Clears grid
void SubtitlesGrid::Clear () {
//if (GetNumberRows() > 0) DeleteRows(0,GetNumberRows());
diagMap.clear();
diagPtrMap.clear();
selMap.clear();
yPos = 0;
AdjustScrollbar();
}
///////////////////////////////////// /////////////////////////////////////
// Read data from ASS file structure // Read data from ASS file structure
void SubtitlesGrid::LoadFromAss (AssFile *_ass,bool keepSelection,bool dontModify) { void SubtitlesGrid::LoadFromAss (AssFile *_ass,bool keepSelection,bool dontModify) {
@ -769,8 +757,6 @@ void SubtitlesGrid::LoadFromAss (AssFile *_ass,bool keepSelection,bool dontModif
for (entryIter cur=ass->Line.begin();cur != ass->Line.end();cur++) { for (entryIter cur=ass->Line.begin();cur != ass->Line.end();cur++) {
curdiag = AssEntry::GetAsDialogue(*cur); curdiag = AssEntry::GetAsDialogue(*cur);
if (curdiag) { if (curdiag) {
//AppendRows(1);
//SetRowToLine(n,curdiag);
diagMap.push_back(cur); diagMap.push_back(cur);
diagPtrMap.push_back(curdiag); diagPtrMap.push_back(curdiag);
selMap.push_back(false); selMap.push_back(false);
@ -793,7 +779,6 @@ void SubtitlesGrid::LoadFromAss (AssFile *_ass,bool keepSelection,bool dontModif
// Finish setting layout // Finish setting layout
AdjustScrollbar(); AdjustScrollbar();
SetColumnWidths();
EndBatch(); EndBatch();
// Commit // Commit
@ -924,11 +909,6 @@ void SubtitlesGrid::PasteLines(int n) {
curdata.Trim(false); curdata.Trim(false);
try { try {
AssDialogue *curdiag = new AssDialogue(curdata); AssDialogue *curdiag = new AssDialogue(curdata);
//AssDialogue *curdiag = new AssDialogue;
//curdiag->data = curdata;
//curdiag->Parse();
//curdiag->UpdateData();
//InsertLine(curdiag,n,true,false);
InsertLine(curdiag,n+inserted,false,false); InsertLine(curdiag,n+inserted,false,false);
inserted++; inserted++;
} }
@ -1212,8 +1192,6 @@ void SubtitlesGrid::SplitLine(int n,int pos,int mode) {
wxString orig = n1->Text; wxString orig = n1->Text;
n1->Text = orig.Left(pos); n1->Text = orig.Left(pos);
n2->Text = orig.Mid(pos); n2->Text = orig.Mid(pos);
//n1->ParseASSTags();
//n2->ParseASSTags();
// Modify time // Modify time
if (mode == 1) { if (mode == 1) {
@ -1260,6 +1238,7 @@ void SubtitlesGrid::CommitChanges(bool force) {
if (playing) video->Play(); if (playing) video->Play();
} }
parentFrame->UpdateTitle(); parentFrame->UpdateTitle();
SetColumnWidths();
Refresh(false); Refresh(false);
} }
@ -1275,26 +1254,6 @@ wxString SubtitlesGrid::GetTempWorkFile () {
} }
/////////////////////////
// Selects visible lines
void SubtitlesGrid::SelectVisible() {
int rows = GetRows();
bool selectedOne = false;
for (int i=0;i<rows;i++) {
if (IsDisplayed(GetDialogue(i))) {
if (!selectedOne) {
SelectRow(i,false);
MakeCellVisible(i,0);
selectedOne = true;
}
else {
SelectRow(i,true);
}
}
}
}
////////////////////////// //////////////////////////
// Set start to video pos // Set start to video pos
void SubtitlesGrid::SetSubsToVideo(bool start) { void SubtitlesGrid::SetSubsToVideo(bool start) {

View file

@ -109,9 +109,6 @@ public:
void LoadFromAss(AssFile *ass=NULL,bool keepSelection=false,bool dontModify=false); void LoadFromAss(AssFile *ass=NULL,bool keepSelection=false,bool dontModify=false);
void CommitChanges(bool force=false); void CommitChanges(bool force=false);
void Clear();
void SelectVisible();
void SetVideoToSubs(bool start); void SetVideoToSubs(bool start);
void SetSubsToVideo(bool start); void SetSubsToVideo(bool start);