/* This file is part of the KDE project
   Copyright (C) 1998-2003 Carsten Pfeiffer <pfeiffer@kde.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, version 2.

   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; see the file COPYING.  If not, write to
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
   Boston, MA 02110-1301, USA.
*/

#ifndef KUICKDATA_H
#define KUICKDATA_H

#include <tqcolor.h>
#include <tqstring.h>

#include "imdata.h"

class TDEConfig;

// values are also used as combobox index defaultswidget.*
enum Rotation { ROT_0=0, ROT_90=1, ROT_180=2, ROT_270=3 };

// hmm, global declaration for now
enum FlipMode { FlipNone = 0, FlipHorizontal = 1, FlipVertical = 2 };

/// A small helper type to track image rotation and flip state at once.
/// Corresponds to a horizontal flip followed by a clockwise rotation.
/// Mathematically speaking it represents operations over Dihedral 4 group.
class FlipRotation
{
public:
    bool flip:1;
    Rotation rot:2;

public:
    FlipRotation(Rotation r = ROT_0, bool f = false) : flip(f), rot(r)
    {}

    /// Inverse the FlipRotation modification
    FlipRotation inverse() const {
	if (flip) {
	    return *this; // reflections are its own inverse
	} else {
	    return FlipRotation ( Rotation( (4-rot) % 4 ), false);
	}
    }

    /// @returns true if the FlipRotation represents an identity/no operation
    bool isNoop() const {
	return *this == FlipRotation();
    }

    /// @returns a FlipRotation which is needed to be applied to the current one to yield rh.
    /// i.e. it solves equation "this * x == rh" for x
    FlipRotation transitionTo(const FlipRotation& rh) const {
	return (inverse() * rh);
    }

    /// Composition of two FlipRotation modifications
    const FlipRotation & operator*=(const FlipRotation& rh) {
	flip ^= rh.flip;
	if (!rh.flip) {
	    rot = Rotation( (     rot + rh.rot ) % 4 );
	} else {
	    rot = Rotation( ( 4 - rot + rh.rot ) % 4 ) ;
	}
	return *this;
    }

    FlipRotation operator*(const FlipRotation& rh) const {
	return FlipRotation(*this) *= rh;
    }

    bool operator==(const FlipRotation &rh) const {
	return rot == rh.rot && flip == rh.flip;
    }

    static FlipRotation vflip() {
	return FlipRotation(ROT_180, true);
    }

    static FlipRotation hflip() {
	return FlipRotation(ROT_0, true);
    }

    static FlipRotation fromFlipMode(FlipMode fm) {
	 FlipRotation rv;
	 if (fm & FlipHorizontal) {
	     rv = FlipRotation::hflip();
	 }
	 if (fm & FlipVertical) {
	     rv *= FlipRotation::vflip();
	 }
	 return rv;
    }
};

class KuickData
{
public:
    KuickData();
    ~KuickData();

    void 	load();
    void 	save();


    ImData 	*idata;

    TQString 	fileFilter;
    uint 	slideDelay;
    uint        slideshowCycles;
    bool        slideshowFullscreen :1;
    bool        slideshowStartAtFirst :1;

    int 	brightnessSteps;
    int 	contrastSteps;
    int 	gammaSteps;

    int 	scrollSteps;
    float	zoomSteps;

    bool startInLastDir      :1;

    bool 	preloadImage     :1;
    bool 	autoRotation     :1;
    bool 	fullScreen       :1;

    // default image modifications
    bool 	isModsEnabled :1;

    bool 	flipVertically   :1;
    bool 	flipHorizontally :1;
    bool 	downScale        :1;
    bool 	upScale          :1;
    int 	maxUpScale;
    float 	maxZoomFactor;
    uint        maxCachedImages;
    Rotation 	rotation;

    TQColor      backgroundColor;


};


extern KuickData* kdata;

#endif
