tiledialog.cpp revision ef9d155a8149d4793471047b3836db719b9e0292
/*
* A simple dialog for creating grid type arrangements of selected objects
*
* Authors:
* Bob Jamison ( based off trace dialog)
* John Cliff
* Other dudes from The Inkscape Organization
*
* Copyright (C) 2004 Bob Jamison
* Copyright (C) 2004 John Cliff
*
* Released under GNU GPL, read the file 'COPYING' for more information
*/
//#define DEBUG_GRID_ARRANGE 1
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <gtk/gtksizegroup.h>
#include "libnr/nr-matrix-ops.h"
#include "verbs.h"
#include "prefs-utils.h"
#include "inkscape.h"
#include "desktop-handles.h"
#include "selection.h"
#include "document.h"
#include "sp-item.h"
#include "tiledialog.h"
/*
* Sort items by their x co-ordinates, taking account of y (keeps rows intact)
*
* <0 *elem1 goes before *elem2
* 0 *elem1 == *elem2
* >0 *elem1 goes after *elem2
*/
int
{
using NR::X;
using NR::Y;
double const a_height = a.dimensions()[Y];
double const b_height = b.dimensions()[Y];
bool a_in_b_vert = false;
a_in_b_vert = true;
a_in_b_vert = true;
a_in_b_vert = true;
} else {
a_in_b_vert = false;
}
if (!a_in_b_vert) {
return -1;
}
return 1;
}
return -1;
}
return 0;
}
/*
* Sort items by their y co-ordinates.
*/
int
{
return 1;
}
return -1;
}
return 0;
}
namespace Inkscape {
namespace UI {
namespace Dialog {
//#########################################################################
//## E V E N T S
//#########################################################################
/*
*
* This arranges the selection in a grid pattern.
*
*/
void TileDialog::Grid_Arrange ()
{
double total_col_width,total_row_height;
col_width = 0;
row_height = 0;
// check for correct numbers in the row- and col-spinners
// set padding to manual values
width = 0;
for (a=0;a<NoOfCols; a++){
}
height = 0;
for (a=0;a<NoOfRows; a++){
}
grid_left = 99999;
grid_top = 99999;
cnt=0;
}
}
}
if (height > row_height) {
row_height = height;
}
}
// require the sorting done before we can calculate row heights etc.
// Calculate individual Row and Column sizes if necessary
cnt=0;
}
}
cnt++;
}
/// Make sure the top and left of the grid dont move by compensating for align values.
if (RowHeightButton.get_active()){
}
if (ColumnWidthButton.get_active()){
}
#ifdef DEBUG_GRID_ARRANGE
#endif
// Calculate total widths and heights, allowing for columns and rows non uniformly sized.
if (ColumnWidthButton.get_active()){
col_widths.clear();
for (a=0;a<NoOfCols; a++){
}
} else {
for (a = 0; a < (int)col_widths.size(); a++)
{
total_col_width += col_widths[a] ;
}
}
if (RowHeightButton.get_active()){
row_heights.clear();
for (a=0;a<NoOfRows; a++){
}
} else {
for (a = 0; a < (int)row_heights.size(); a++)
{
total_row_height += row_heights[a] ;
}
}
// Fit to bbox, calculate padding between rows accordingly.
if (!SpaceManualRadioButton.get_active()){
#ifdef DEBUG_GRID_ARRANGE
g_print("\n row = %f col = %f selection x= %f selection y = %f", total_row_height,total_col_width, b.extent(NR::X), b.extent(NR::Y));
#endif
}
/*
Horizontal align - Left = 0
Centre = 1
Right = 2
Vertical align - Top = 0
Middle = 1
Bottom = 2
X position is calculated by taking the grids left co-ord, adding the distance to the column,
then adding 1/2 the spacing multiplied by the align variable above,
Y position likewise, takes the top of the grid, adds the y to the current row then adds the padding in to align it.
*/
// Calculate row and column x and y coords required to allow for columns and rows which are non uniformly sized.
for (a=0;a<NoOfCols; a++){
}
for (a=0;a<NoOfRows; a++){
}
cnt=0;
}
// original before I started fecking about with it.
// new_x = grid_left + (((col_width - width)/2)*HorizAlign) + (( col_width + paddingx ) * (cnt % NoOfCols));
// new_y = grid_top + (((row_height - height)/2)*VertAlign) +(( row_height + paddingy ) * (cnt / NoOfCols));
NR::Point move = NR::Point(new_x - b.min()[NR::X], b.min()[NR::Y] - new_y); // why are the two args the opposite ways round???
cnt +=1;
}
}
NRRect b;
_("Arrange in a grid"));
}
//#########################################################################
//## E V E N T S
//#########################################################################
void TileDialog::_apply()
{
Grid_Arrange();
}
/**
* changed value in # of columns spinbox.
*/
void TileDialog::on_row_spinbutton_changed()
{
// quit if run by the attr_changed listener
if (updating) {
return;
}
// in turn, prevent listener from responding
updating = true;
updating=false;
}
/**
* changed value in # of rows spinbox.
*/
void TileDialog::on_col_spinbutton_changed()
{
// quit if run by the attr_changed listener
if (updating) {
return;
}
// in turn, prevent listener from responding
updating = true;
updating=false;
}
/**
* changed value in x padding spinbox.
*/
void TileDialog::on_xpad_spinbutton_changed()
{
}
/**
* changed value in y padding spinbox.
*/
void TileDialog::on_ypad_spinbutton_changed()
{
}
/**
*/
{
if (RowHeightButton.get_active()) {
} else {
}
}
/**
*/
{
if (ColumnWidthButton.get_active()) {
} else {
}
}
/**
* changed value in columns spinbox.
*/
{
// quit if run by the attr_changed listener
if (updating) {
return;
}
// in turn, prevent listener from responding
updating = true;
updating=false;
}
/**
* changed value in rows spinbox.
*/
{
// quit if run by the attr_changed listener
if (updating) {
return;
}
// in turn, prevent listener from responding
updating = true;
updating=false;
}
/**
* changed Radio button in Spacing group.
*/
void TileDialog::Spacing_button_changed()
{
if (SpaceManualRadioButton.get_active()) {
} else {
}
}
/**
* changed Radio button in Vertical Align group.
*/
void TileDialog::VertAlign_changed()
{
if (VertTopRadioButton.get_active()) {
VertAlign = 0;
} else if (VertCentreRadioButton.get_active()){
VertAlign = 1;
} else if (VertBotRadioButton.get_active()){
VertAlign = 2;
}
}
/**
* changed Radio button in Vertical Align group.
*/
void TileDialog::HorizAlign_changed()
{
if (HorizLeftRadioButton.get_active()) {
HorizAlign = 0;
} else if (HorizCentreRadioButton.get_active()){
HorizAlign = 1;
} else if (HorizRightRadioButton.get_active()){
HorizAlign = 2;
}
}
/**
* Desktop selection changed
*/
void TileDialog::updateSelection()
{
double col_width, row_height;
// quit if run by the attr_changed listener
if (updating) {
return;
}
col_width=0;
row_height=0;
// in turn, prevent listener from responding
updating = true;
// Update the number of rows assuming number of columns wanted remains same.
// if the selection has less than the number set for one row, reduce it appropriately
}
} else {
}
updating=false;
}
/*##########################
## Experimental
##########################*/
static void updateSelectionCallback(Inkscape::Application *inkscape, Inkscape::Selection *selection, TileDialog *dlg)
{
}
//#########################################################################
//## C O N S T R U C T O R / D E S T R U C T O R
//#########################################################################
/**
* Constructor
*/
{
// bool used by spin button callbacks to stop loops where they change each other.
updating = false;
// could not do this in gtkmm - there's no Gtk::SizeGroup public constructor (!)
{
// Selection Change signal
g_signal_connect ( G_OBJECT (INKSCAPE), "change_selection", G_CALLBACK (updateSelectionCallback), this);
}
#define MARGIN 2
//##Set up the panel
int selcount = 1;
}
/*#### Number of Rows ####*/
double PerCol = 1;
#ifdef DEBUG_GRID_ARRANGE
#endif
NoOfRowsSpinner.signal_changed().connect(sigc::mem_fun(*this, &TileDialog::on_col_spinbutton_changed));
if (AutoRow>0)
AutoRowSize=true;
else
AutoRowSize=false;
tips.set_tip(RowHeightButton, _("If not set, each row has the height of the tallest object in it"));
RowHeightButton.signal_toggled().connect(sigc::mem_fun(*this, &TileDialog::on_RowSize_checkbutton_changed));
{
/*#### Radio buttons to control vertical alignment ####*/
VertCentreRadioButton.signal_toggled().connect(sigc::mem_fun(*this, &TileDialog::VertAlign_changed));
if (VertAlign == 0) {
}
else if (VertAlign == 1) {
}
else if (VertAlign == 2){
}
}
/*#### Label for X ####*/
/*#### Number of columns ####*/
NoOfColsSpinner.signal_changed().connect(sigc::mem_fun(*this, &TileDialog::on_row_spinbutton_changed));
if (AutoCol>0)
AutoColSize=true;
else
AutoColSize=false;
tips.set_tip(ColumnWidthButton, _("If not set, each column has the width of the widest object in it"));
ColumnWidthButton.signal_toggled().connect(sigc::mem_fun(*this, &TileDialog::on_ColSize_checkbutton_changed));
{
/*#### Radio buttons to control horizontal alignment ####*/
HorizLeftRadioButton.signal_toggled().connect(sigc::mem_fun(*this, &TileDialog::HorizAlign_changed));
HorizCentreRadioButton.signal_toggled().connect(sigc::mem_fun(*this, &TileDialog::HorizAlign_changed));
HorizRightRadioButton.signal_toggled().connect(sigc::mem_fun(*this, &TileDialog::HorizAlign_changed));
if (HorizAlign == 0) {
}
else if (HorizAlign == 1) {
}
else if (HorizAlign == 2) {
}
}
{
/*#### Radio buttons to control spacing manually or to fit selection bbox ####*/
SpaceByBBoxRadioButton.signal_toggled().connect(sigc::mem_fun(*this, &TileDialog::Spacing_button_changed));
SpaceManualRadioButton.signal_toggled().connect(sigc::mem_fun(*this, &TileDialog::Spacing_button_changed));
}
{
/*#### Y Padding ####*/
YPadSpinner.signal_changed().connect(sigc::mem_fun(*this, &TileDialog::on_ypad_spinbutton_changed));
}
{
}
{
/*#### X padding ####*/
XPadSpinner.signal_changed().connect(sigc::mem_fun(*this, &TileDialog::on_xpad_spinbutton_changed));
}
if (SpacingType>0) {
ManualSpacing=true;
} else {
ManualSpacing=false;
}
//## The OK button
}
} //namespace Dialog
} //namespace UI
} //namespace Inkscape
//#########################################################################
//## E N D O F F I L E
//#########################################################################
/*
Local Variables:
mode:c++
c-file-style:"stroustrup"
c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
indent-tabs-mode:nil
fill-column:99
End:
*/
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :